0

In GUN C manual, 6.30 Declaring Attributes of Functions, it states:

You may also specify attributes with __ preceding and following each keyword. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use __noreturn__ instead of noreturn.

Does this mean that user can specify customized attributes? Or what else? I'm definitely confused, could anyone help, or give me some samples?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Bill Wang
  • 197
  • 1
  • 10

1 Answers1

1

What it's saying is that a header file might have done:

#define noreturn 3

If you then try to declare a function as:

void fatal () __attribute__ ((noreturn));

it will be processed as if you'd written:

void fatal () __attribute__ ((3));

which is not what you want. So you can write instead:

void fatal () __attribute__ ((__noreturn__));

This is safe because users are not allowed to define macros with names beginning with two underscores, these names are reserved for the implementation. See What are the rules about using an underscore in a C++ identifier?

Community
  • 1
  • 1
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Hi, @Barmar, thank you:), in your reply, *users are not allowed to define macros with names beginning with two underscores*, I test on gcc v4.7.2, with `#define __foo__ 2`, and this is fine with `gcc -Wall test.c`. Does this limitation just coding conversion or GNU limitation? or something else? – Bill Wang Apr 14 '13 at 04:07
  • They're programming restrictions specified by the language. See the question I just added a link to. – Barmar Apr 14 '13 at 04:12