0

Today I started learning OpenCL when I came across function specifier like _kernel. Than I searched for it and I found many function specifier like _inline _noreturn. I want to know what is a function specifier and what's its usage? I have read many C programming books but never found such term?

_Noreturn 

Is the above specifier similar to void?

4

3 回答 3

2

Here's a good link explaining function specifiers

I have quoted an excerpt that more accurately answers your specific question:

_Noreturn (since C11) - specifies that the function does not return to where it was called from.

于 2015-07-06T02:16:07.620 回答
0

You need a book familiar with C11 (ISO/IEC 9899:2011). The keyword _Noreturn is a new function specifier, like inline (which was added in C99 or ISO/IEC 9899:1999). It is not a type (or absence of type) as with void. _Noreturn means that the function does not return. For example, the C11 standard declares that exit() is a function that does not return:

#include <stdlib.h>
_Noreturn void exit(int status);

There's also a header, <stdnoreturn.h>, that provides

#define noreturn _Noreturn

Note that the name _Noreturn is from the namespace reserved for the implementation; the name noreturn could have been used by a user. Any code broken by _Noreturn was already abusing the namespace reserved for the implementation.

You'll also find older code using compiler-specific mechanisms, such as __attribute__((noreturn)) in GCC.

In general, function specifiers identify properties about a function that are not directly the type of the function. For example, inline has implications that the function may be suitable for inlining — it is a hint to the compiler/optimizer. Similarly, _Noreturn is a hint to the compiler/optimizer that if the function is called, control will never return to the calling code.

于 2015-07-06T02:12:00.497 回答
0

I have a full machine-readable C11 grammar (with GNU extensions).

Quoting the relevant parts here:

function-definition:
    declaration-specifiers_opt declarator declaration-list_opt compound-statement

declaration-specifiers:
    storage-class-specifier declaration-specifiers_opt
    type-specifier declaration-specifiers_opt
    type-qualifier declaration-specifiers_opt
    function-specifier declaration-specifiers_opt
    alignment-specifier declaration-specifiers_opt
    attributes declaration-specifiers_opt

function-specifier:
    inline
    _Noreturn

I would accept pull requests to add new grammars for other compilers/languages since I'm not aware of anyone else collecting them.

于 2015-07-06T02:37:35.583 回答