Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-13-2003, 08:42 AM
|
#1
|
Member
Registered: Nov 2003
Posts: 77
Rep:
|
Question about function prototypes
hi,Im learning c from a book written prior to today's ANSI standard and I noticed some things are quite different
1-Must a function which is called in a file before it is defined,be declared with function prototype?
2-Can a Function prototype be declared in each function that calls this particular function,instead of being declared in the beginning of the file?
3-How about function that is defined before it is declared?Is then function prototype not needed?
thank you
|
|
|
12-13-2003, 10:17 AM
|
#2
|
Member
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231
Rep:
|
The answer to it are
1. the function prototype is required only when it is called before it is defined during the run of the code....
2. yes the function prototype can be declared in each function that calls this particular function, instead of being declared in the beginning of the file...
if it is done so then this declaration would be local to the function... a better practise is to define all the functions at the begining of the file... before the main
3. it is immaterial to declare if the function is defined before it is first called....
|
|
|
12-13-2003, 10:29 AM
|
#3
|
Member
Registered: Nov 2003
Posts: 77
Original Poster
Rep:
|
hi
Quote:
Originally posted by hiteshmaisheri
The answer to it are
1. the function prototype is required only when it is called before it is defined during the run of the code....
|
But my program works even if I don't use function prototype(assuming function is called prior to its definition)
thank you so much for helping
|
|
|
12-15-2003, 12:36 AM
|
#4
|
Member
Registered: Sep 2003
Location: Raleigh, NC, USA
Distribution: Fedora
Posts: 88
Rep:
|
Just because it works, it doesn't mean it is correct. It may only work with your test case or it could fail on other compilers. The compiler uses the function prototype to determine if the call you are making is of the correct type, etc. If the compiler doesn't know, it guesses. I think it basically assumes that everything in the function call is an int. Depending on what you are doing, that may or may not work.
This is one of those cases where C doesn't do a lot to stop you from shooting yourself in the foot. It is up to the programmer to protect himself by using the prototypes.
|
|
|
12-15-2003, 10:10 AM
|
#5
|
Member
Registered: Nov 2003
Location: Kerala, India
Distribution: Red Hat, Knoppix, Mandrake, FreeBSD
Posts: 231
Rep:
|
certain features if the work may be due to the non compliance with the ansi c.... just use the gcc.... to get better results
|
|
|
All times are GMT -5. The time now is 05:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|