Re: __attribute__ , noreturn

From: Erik Andersen (andersen@xmission.com)
Date: Mon Mar 13 2000 - 13:19:06 EST


On Mon Mar 13, 2000 at 04:44:16PM +0500, Tiger wrote:
> Can some one explain what exactly it does __attribute__ and what is
> noretun

gcc uses "__attribute__" to specify compiler directives instead of the
traditional "#pragma" since #pragma behaviors are totally unportable and cannot
be placed into macros. Consider this code:

    #include<stdlib.h>
    #include <stdio.h>

    __attribute__ ((noreturn)) void message1(const char *msg)
    {
        printf(msg);
        exit(0);
    }

    int main( void)
    {
        message1("Hello\n");
    }

Without the __attribute__ ((noreturn)), the compiler would complain that
"control reaches end of non-void function" in main(). By using the attribute
we can give the compiler the hint that control will never go back to main(),
and it doesn't need to give a warning.

 -Erik

--
Erik B. Andersen   Web:    http://www.xmission.com/~andersen/ 
                   email:  andersee@debian.org
--This message was written using 73% post-consumer electrons--

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Mar 15 2000 - 21:00:25 EST