Tuesday, May 8, 2012

Solution: function declaration isn't a prototype in C

This problem is seen when you declare a function separately for example:

int getData();

and then say somewhere within your code this function is defined as:

int getData() {

The reason for this error is that C treats a function defn  fun1() and fun1(void) as different functions. If you change the declaration above as:
int getData(void);

your problem will be solved.

This was nicely explained by a related post on some forum:

In C foo() and foo(void) are different functions. foo() accepts an infinite number of arguments, while foo(void) accepts 0 arguments. In C++ they mean the same thing. I suggest that you use void consistently when you mean no arguments.
If you have a variable a, "extern int a;" is a way to tell the compiler that 'a' is a symbol that might be present in a different translation unit (c compiler speak for source file), don't resolve it until link time. On the other hand, symbols which are function names are anyway resolved at link time. The meaning of a storage class specifier on a function (extern, static) only affects its visibility and extern is the default, so extern is actually unnecessary.


Anonymous said...

Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that
automatically tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

my homepage garbage disposal

Anonymous said...

Hi, always i used to check website posts here in the early hours in the dawn, because i enjoy to gain knowledge of more and more.

Here is my site: carry pets
My site > hound is obedient loyal loving

Anonymous said...

It is in point of fact a great and helpful piece of
information. I'm satisfied that you shared this useful info with us. Please keep us up to date like this. Thank you for sharing.

Also visit my web-site ... mazda rx 8 2004

Post a Comment