what does #pragma do?

This is a discussion on what does #pragma do? within the C++ Programming forums, part of the General Programming Boards category; Hi, I can't seem to find a good resource that clearly explains what #pragma does. I saw it in this ...

  1. #1
    cbc
    cbc is offline
    Registered User
    Join Date
    Oct 2003
    Posts
    4

    what does #pragma do?

    Hi,

    I can't seem to find a good resource that clearly explains what #pragma does. I saw it in this code:

    #ifdef _DEBUG
    #pragma comment( lib, "MyLib_d" )
    #elseif
    #pragma comment( lib, "MyLib" )
    #endif

    Can anyone explain it to me? Thanks.

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    From MSDN with Visual Studio 6.0 Professional:

    Pragma Directives
    Each implementation of C and C++ supports some features unique to its host machine or operating system. Some programs, for instance, need to exercise precise control over the memory areas where data is placed or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating-system-specific features while retaining overall compatibility with the C and C++ languages. Pragmas are machine- or operating-system-specific by definition, and are usually different for every compiler.

    Syntax

    #pragma token-string

    The token-string is a series of characters that gives a specific compiler instruction and arguments, if any. The number sign (#) must be the first non-white-space character on the line containing the pragma; white-space characters can separate the number sign and the word pragma. Following #pragma, write any text that the translator can parse as preprocessing tokens. The argument to #pragma is subject to macro expansion.

    If the compiler finds a pragma it does not recognize, it issues a warning, but compilation continues.

    Pragmas can be used in conditional statements, to provide new preprocessor functionality, or to provide implementation-defined information to the compiler. The C and C++ compilers recognize the following pragmas:

    alloc_text comment init_seg1 optimize
    auto_inline component inline_depth pack
    bss_seg data_seg inline_recursion pointers_to_members1
    check_stack function intrinsic setlocale
    code_seg hdrstop message vtordisp1
    const_seg include_alias once warning


    1. Supported only by the C++ compiler.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Try using online help
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. labels inside the code #pragma mark label
    By nacho4d in forum C++ Programming
    Replies: 6
    Last Post: 01-11-2009, 02:50 AM
  2. #pragma pack(push,bitmap_data,1) ?
    By te5la in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2008, 04:38 PM
  3. Programming a PIC 16F84 microcontroller in C
    By Iahim in forum C Programming
    Replies: 1
    Last Post: 05-13-2004, 03:23 PM
  4. #pragma ?
    By dat in forum C++ Programming
    Replies: 2
    Last Post: 04-02-2003, 08:14 AM
  5. what is a pragma comment?
    By Shadow12345 in forum C++ Programming
    Replies: 9
    Last Post: 11-25-2002, 05:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21