Doubts in C

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2005
Posts: 15
Reputation: akshayabc is an unknown quantity at this point 
Solved Threads: 0
akshayabc akshayabc is offline Offline
Newbie Poster

Doubts in C

 
0
  #1
Dec 15th, 2005
Plz answer my these C doubts-
Q. 1- If i have 3 source files and i declare a static variable in the source file s2.c then which statement is true:-
That static variable is created when the program starts executing and is destroyed when the whole program finishes executing.
OR
That static variable is created when the source file s2.c starts executing and is destroyed when the file s2.c finishes executing.
(I dont want to know abt the scope of the static variable)

Q. 2- Header contains the declarations of functions & variables and in C it is not necessary(even though its safer) to give a prototype of a function before its use in the program. So does it mean that if we dont include a header file which declares a function X(), even then we can use that function(bcoz the header file contains only the prototype of the function, which is not necessary in C).

Q. 3- What do the .obj and .lib files contain?
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 78
Reputation: perniciosus is an unknown quantity at this point 
Solved Threads: 4
perniciosus's Avatar
perniciosus perniciosus is offline Offline
Junior Poster in Training

Re: Doubts in C

 
0
  #2
Dec 15th, 2005
Q1: Alternative 1
Q2: If the function X returns an integer, uses standard calling convention (and possibly is not dynamically linked, I'm not sure about the actual meaning of __declarespec(import)).
Q3: .obj is most oftenly compiled code, all functions and variables from a compiled source file. .lib I think contains either multiple such object files in a kind of archive, or link information for dynamic linkage (thought I'm not quite sure of this since it mostly just work for me).
/pern.*/i

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. Albert Einstein
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 716
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Doubts in C

 
0
  #3
Dec 15th, 2005
>Plz answer my these C doubts-
"Doubt" is sometimes synonymous with "question", but not in this case. It's very common to ignorantly use doubt in place of question, and it's usually wrong. What you have a C questions, not C doubts.

>I dont want to know abt the scope of the static variable
Obviously, since your question has nothing to do with scope and everything to do with storage duration. There's no need to qualify your question as such because if someone starts talking about scope, you know that they're not qualified to answer it correctly.

>in C it is not necessary(even though its safer) to give a
>prototype of a function before its use in the program.
Wrong on two counts. First, the latest C standard removed that dangerous feature. Second, even in C89, the implicit function declaration doesn't always work depending on the arguments and return value of the function in question.

>What do the .obj and .lib files contain?
It depends heavily on the compiler and linker in question. The generic answer is that object files contain object code, which is the primary output of the compiler. The linker then uses the object code to piece together an executable file. Library files are basically independent collections of object code and links.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1
Reputation: see2penc is an unknown quantity at this point 
Solved Threads: 0
see2penc's Avatar
see2penc see2penc is offline Offline
Newbie Poster

Re: Doubts in C

 
0
  #4
Mar 17th, 2007
Originally Posted by akshayabc View Post
Plz answer my these C doubts-
Q. 1- If i have 3 source files and i declare a static variable in the source file s2.c then which statement is true:-
That static variable is created when the program starts executing and is destroyed when the whole program finishes executing.
OR
That static variable is created when the source file s2.c starts executing and is destroyed when the file s2.c finishes executing.
(I dont want to know abt the scope of the static variable)

http://www.daniweb.com/techtalkforum...s/solution.gifA)second statement is true

Q. 2- Header contains the declarations of functions & variables and in C it is not necessary(even though its safer) to give a prototype of a function before its use in the program. So does it mean that if we dont include a header file which declares a function X(), even then we can use that function(bcoz the header file contains only the prototype of the function, which is not necessary in C).

http://www.daniweb.com/techtalkforum...s/solution.gifA)function prototype is necessary only in C++ as its one of the syntax that u should give function definion b4 u use it in main() as function prototype.
In C its not needed 2 declare the prototype of a function.
The answer 4 ur question is yes if u r working with a c compiler.

Q. 3- What do the .obj and .lib files contain?
http://www.daniweb.com/techtalkforum...s/solution.gifA) .obj and .lib are the files with extension obj and lib.

.obj refer to the files related to have object code contained in them.
.lib refer to files related to library functions.
KVPRAJ
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Doubts in C

 
0
  #5
Mar 17th, 2007
Originally Posted by Narue View Post
>Plz answer my these C doubts-
"Doubt" is sometimes synonymous with "question", but not in this case. It's very common to ignorantly use doubt in place of question, and it's usually wrong. What you have a C questions, not C doubts.
I think this is something taught in India. The only posters that have 'doubts' seem to be from there...
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC