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?

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

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?
They're programming restrictions specified by the language. See the question I just added a link to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.