Noreturn function returns

When I compile the C program below, I get this warning: 'noreturn' function does return . This is the function:

 void hello(void){ int i; i=1; } 

Why can this happen? The whole call to this function is hello();

EDIT: Full error output:

  home.c: In function 'hello': hhme.c:838:7: error: variable 'i' set but not used [-Werror=unused-but-set-variable] home.c:840:1: error: 'noreturn' function does return [-Werror] cc1: all warnings being treated as errors make: *** [home.o] Error 1 
+7
source share
2 answers

You could tell gcc that some function never returns. This allows certain optimizations and helps to avoid false warnings of uninitialized variables.

This is done using the noreturn attribute:

 void func() __attribute__ ((noreturn)); 

If the function returns despite the noreturn attribute, the compiler generates a warning that you see (which in your case will noreturn into an error).

Since you are unlikely to use noreturn in your code, the likely explanation is that you have a function whose name comes across the standard noreturn function, as shown in the following example:

 #include <stdlib.h> void exit(int) { } // warning: 'noreturn' function does return [enabled by default] 

Here my exit collides with exit(3) .

Another obvious candidate for such a collision is abort(3) .

Of course, if your function is really called hello() , the culprit is almost certainly located somewhere inside your code base.

+24
source

Most likely, the function is marked with __attribute__((noreturn)) . However, it does return (when the control reaches the end of the irs body, since it does not enter an infinite loop, it does not call other "noreturn" functions, etc.)

I don’t see what your point is 1. Mark the function as non-returning, 2. write a function that does nothing - maybe you could just fix both?

+4
source

All Articles