tags:

views:

222

answers:

2

I am working with code from the GNU core utils, and find that the void usage() function is apparently set with the attribute "noreturn". Well, I am modifying the function, and I wish it to return (I removed the call to exit()). The compiler still complains that a "noreturn" function returns, and when using the Eclipse CDT debugger, stepping thorugh the code is anomolous - I skip over lines of code. I do not see the function be set in the .c file, and there is no .h file for this .c file.

The file is df.c. I have renamed the file df_call.c. How can the compiler be finding this attribute? How can I unset it?

Thanks.

======= Thanks to all contributors for their help! The short answer is "the usage() function found in GNUutils 7.4 is prototyped in system.h as 'void usage (int status) ATTRIBUTE_NORETURN'. Changing to 'void usage (int status); /*ATTRIBUTE_NORETURN;*/' resolved the issue for me, but leaves the problem of a modified system.h.

The long answer is: The GNU c compiler supports assigning attributes to functions (see http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) one of which is "noreturn". The syntax is "attribute ((noreturn))" (see http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax) but is often macro'd to ATTRIBUTE_NORETURN. If the attribute is set, and in this case one tries to return from the function, the executable compiles with a complaint, but compiles and runs. It will, however, behave unexpectedly (skipping over src lines in my case, maybe due to the optimization). The debugger in Eclipse CDT actually jumps past lines of code, leading the developer to doubt his senses.

+1  A: 

I would suggest preprocessing the source file so you have the entire contents of the translation unit available to you. From there I would search for usage to see where the gcc attribute may be coming from. You should also check possible gcc command line arguments and/or macros that may be affecting your function declaration.

fbrereto
I am calling directly to gcc, so I am not doing any compile-line defs, and in fact am using minimal args.
cvsdave
A: 

run gcc -E instead of gcc -c and have a look at the results. With luck it will be clear there the noreturn attribute is coming from.

Another alternative would be to do what I do, which is avoid using gcc-specific extensions.

gcc -std=c99 -pedantic

may tame the beast.

Norman Ramsey