#pragma [C++ Reference]
Keywords: preprocessor,pragma
Date: 2009-10-12T16:49:39-0700

## #pragma

        #pragma lexems

The #pragma command gives the programmer the ability to tell the compiler to do certain things. Since the #pragma command is implementation specific, uses vary from compiler to compiler. One option might be to trace program execution.

Below are some compiler families, the operating system on which they're found and the pragma directives which are part of that implementation

Also pragma is used to allow the programmer to call a function before main is called or after main exits.

    #pragma startup fun() //The function must have return void type & no parameters.
    #pragma exit fun1()

### GNU C Compiler (GCC) - GNU/Linux, BSD, GNU/Hurd, GNU/Darwin/Mac OS X, Windows (MinGW)

#### redefine_extname

        #pragma redefine_extname printf prnt

Gives C functions a different programmer defined symbol when translated to assembly language.

#### extern_prefix

        #pragma extern_prefix ext_ // begin prefixing
        // your external symbols with the assembly prefix is here
        #pragma extern_prefix // end prefixing

Prefixes all external function assembly symbols with the string prefix. Another #pragma extern_prefix will end prefixing of externals.

#### pack

        #pragma pack(64) // optimize all subsequent classes, unions, and structures for 64 bit code

Packing is an optimization method that makes the members of structures, classes, and unions align to a factor of the packing boundary. This usually makes it easier (thus faster) for the processor to access data since it's packed to align with what the processor is used to dealing with, however it costs memory by having random unnecessary garbage data inserted to align the code with the pack. the numerical value in parenthesis must be a factor of 2 (2, 4, 8, 16, 32, 64….). There are other ways to use “pack” and they're described below but above is the simplest and most common way. you can use

    #pragma pack() /* with empty parenthesis */

to reset the packing to the compiler default.

← #pragma pack(push) and #pragma pack(pop) are on the way, I'm still researching them and their functionality. -/> ← This document is still under construction, I intend to continue adding compilers and their pragma options instead of leaving this largely blank. -GinoMan -/>