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?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
RajSharma
  • 1,941
  • 3
  • 21
  • 34
  • Note that while `_inline` and `_noreturn` are actual C keywords, `_kernel` is an OpenCL define. It has nothing to do with your operating system's runtime -- in fact it runs on the graphics card. – Blindy Jul 06 '15 at 02:18
  • 2
    @Blindy: Neither `_inline` nor `_noreturn` is a C keyword; the keywords are `inline` and `_Noreturn`. – Jonathan Leffler Jul 06 '15 at 02:19
  • That's semantics, they directly match. My point was that `_kernel` isn't in the same category as the OP implied. – Blindy Jul 06 '15 at 04:23

3 Answers3

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.

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
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.

o11c
  • 15,265
  • 4
  • 50
  • 75