Predefined Pragmas (The GNU D Compiler)

### 2.6 Predefined Pragmas ¶

The `pragma` operator is used as a way to pass special information to the implementation and allow the addition of vendor specific extensions. The standard predefined pragmas are documented by the D language specification hosted at https://dlang.org/spec/pragma.html#predefined-pragmas. A D compiler must recognize, but is free to ignore any pragma in this list.

Where a pragma is ignored, the GNU D compiler will emit a warning when the `-Wunknown-pragmas` option is seen on the command-line.

`pragma(crt_constructor)`

  `pragma(crt_constructor)` annotates a function so it is run after the C runtime library is initialized and before the D runtime library is initialized. Functions with this pragma must return `void`.

      pragma(crt_constructor) void init() { }

`pragma(crt_destructor)`

  `pragma(crt_destructor)` annotates a function so it is run after the D runtime library is terminated and before the C runtime library is terminated. Calling `exit` function also causes the annotated functions to run. Functions with this pragma must return `void`.

      pragma(crt_destructor) void init() { }

`pragma(inline)`
`pragma(inline, false)`
`pragma(inline, true)`

  `pragma(inline)` affects whether functions are declared inlined or not. The pragma takes two forms. In the first form, inlining is controlled by the command-line options for inlining.

  Functions annotated with `pragma(inline, false)` are marked uninlinable. Functions annotated with `pragma(inline, true)` are always inlined.

`pragma(lib)`

  This pragma is accepted, but has no effect.

      pragma(lib, "advapi32");

`pragma(linkerDirective)`

  This pragma is accepted, but has no effect.

      pragma(linkerDirective, "/FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2");

`pragma(mangle)`

  `pragma(mangle, "symbol_name")` overrides the default mangling for a function or variable symbol. The symbol name can be any expression that must evaluate at compile time to a string literal. This enables linking to a symbol which is a D keyword, since an identifier cannot be a keyword.

  Targets are free to apply a prefix to the user label of the symbol name in assembly. For example, on `x86_64-apple-darwin`, ‘`symbol_name`’ would produce ‘`_symbol_name`’. If the mangle string begins with ‘`*`’, then `pragma(mangle)` will output the rest of the string unchanged.

      pragma(mangle, "body")
      extern(C) void body_func();

      pragma(mangle, "function")
      extern(C++) struct _function {}

`pragma(msg)`

  `pragma(msg, "message")` causes the compiler to print an informational message with the text ‘`message`’. The pragma accepts multiple arguments, each to which is evaluated at compile time and then all are combined into one concatenated message.

      pragma(msg, "compiling...", 6, 1.0); // prints "compiling...61.0"

`pragma(printf)`
`pragma(scanf)`

  `pragma(printf)` and `pragma(scanf)` specifies that a function declaration with `printf` or `scanf` style arguments that should be type-checked against a format string.

  A printf-like or scanf-like function can either be an `extern(C)` or `extern(C++)` function with a format parameter accepting a pointer to a 0-terminated `char` string, immediately followed by either a `...` variadic argument list or a parameter of type `va_list` as the last parameter.

      extern(C):
      pragma(printf)
      int printf(scope const char* format, scope const ...);

      pragma(scanf)
      int vscanf(scope const char* format, va_list arg);

`pragma(startaddress)`

  This pragma is accepted, but has no effect.

      void foo() { }
      pragma(startaddress, foo);