[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] Need a little C programming help



Those errors can occur if you include files within a C block.
For example, the following works well:

#include <stdlib.h>
int main() {}

but this fails with exactly the errors you have seen:

int main() {
#include <stdlib.h>
}

This can happen sometimes by accident, for example when you
are conditionally compiling braces within #ifdef ... #endif
and forget one of the matching end braces, like

#ifdef SOME_CONDITION
{
#endif

...

/* here we should have the same condition with the closing braces

#include <stdlib.h>	/* this will fail */

The compiler sees the inline functions declared in the header file
inside another function, takes it as nested function (a gcc extension)
and in your case throws an error because the function does not meet
some specific criteria (obviously a local nested function can not
have an "extern" binding).

If you dont find the mistake easily, try checking the precompiled
output. cc -E -o swrc.I swrc.c preprocesses the c file into swrc.I
which you can then check for non-matching braces.

Regards,

	Andreas

Mike Reinehr wrote:
[...]
> This evening, I had to make very minor change to the program but when I 
> attempted to compile I received the following error output:
> 
> cmr@gladsheim:~/tmp$ cc swrc.c
> In file included from /usr/include/sys/types.h:219,
>                  from /usr/include/stdlib.h:433,
>                  from swrc.c:5:
> /usr/include/sys/sysmacros.h: In function `main':
> /usr/include/sys/sysmacros.h:43: error: nested function `gnu_dev_major' 
> declared `extern'
[...]



Reply to: