What is #pragma once used for

Discussion in 'C++' started by raashid bhatt, Mar 27, 2008.

  1. What is #pragma once used for
    and
    what is #WIN#@_LEN_AND_MEAN
    raashid bhatt, Mar 27, 2008
    #1
    1. Advertising

  2. "raashid bhatt" <> wrote in message
    news:...
    > What is #pragma once used for
    > and
    > what is #WIN#@_LEN_AND_MEAN


    It is a preprocessor directive. You'd have to look it up in the
    documentation for your compiler. Judging by your second question, MSDN
    Library would be the place to look.
    The first is usually for turning off compiler warnings and the second is an
    arifact from the old days when someone would make a windows application
    using the native C++ windows API without any MFC bloat. I don't know if it
    makes any difference anymore or not, but MSDN would. Hell, I have problems
    getting answers to anything that is not .NET related from MS forums these
    days.
    Christopher Pisz, Mar 27, 2008
    #2
    1. Advertising

  3. raashid bhatt

    Guest

    On 27 Mrz., 06:12, raashid bhatt <> wrote:
    > What is #pragma once used for
    > and
    > what is #WIN#@_LEN_AND_MEAN


    #pragma once directs the preprocessor of MS Visual C++ to #include the
    file only one time per compilation unit, even if more than one
    #include for the file is encountered. #pragma is the standard way to
    add non-standard behavior to C++; other compilers will just ignore the
    line. A better way to achieve the effect would be

    xyz.h:

    #ifndef _XYZ_H_INCLUDED
    #define _XYZ_H_INCLUDED
    .... /* remainder of file */
    #endif

    The definition of the WIN_LEAN_AND_MEAN preprocessor symbol in MS
    Visual C++ excludes rarely used stuff from the platform specific
    #include files (windows.h, ...).

    best,

    Michael
    , Mar 27, 2008
    #3
  4. raashid bhatt wrote:
    > What is #pragma once used for


    It is not standard, although it might become one eventually. '#pragma once' is
    supposed to be used in header files. It tells the compiler that this particular
    header file needs to be included into each translation unit no more than once.
    If it is included more than once, the compiler can safely ignore the second and
    all the further inclusions.

    > what is #WIN#@_LEN_AND_MEAN


    This has nothing to do with standard C++. Consult your compiler documentation
    for this or ask in MS compiler specific forum.

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Mar 27, 2008
    #4
  5. raashid bhatt

    James Kanze Guest

    On Mar 27, 6:12 am, raashid bhatt <> wrote:
    > What is #pragma once used for


    Making code non-portable.

    > and
    > what is #WIN#@_LEN_AND_MEAN


    Locking you 100% into a specific compiler vendor.

    I've never used either in my code, and don't expect I ever will.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Mar 27, 2008
    #5
  6. raashid bhatt

    Krice Guest

    On 27 maalis, 11:36, James Kanze <> wrote:
    > Locking you 100% into a specific compiler vendor.


    I guess other compilers also have compiler specific stuff,
    like __attribute() in gcc, which doesn't work in VC++ and
    is not a part of C++ standard.
    Krice, Mar 27, 2008
    #6
  7. raashid bhatt

    James Kanze Guest

    On Mar 27, 11:34 am, Krice <> wrote:
    > On 27 maalis, 11:36, James Kanze <> wrote:


    > > Locking you 100% into a specific compiler vendor.


    > I guess other compilers also have compiler specific stuff,
    > like __attribute() in gcc, which doesn't work in VC++ and
    > is not a part of C++ standard.


    And which, of course, I don't use either. (To be fair to
    Microsoft: the very name used screamed Windows. It's hard to
    pretend that you didn't at least suspect that it wasn't 100%
    portable.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Mar 27, 2008
    #7
  8. raashid bhatt

    Andy Champ Guest

    OT: Re: What is #pragma once used for

    wrote:
    > On 27 Mrz., 06:12, raashid bhatt <> wrote:
    >> What is #pragma once used for
    >> and
    >> what is #WIN#@_LEN_AND_MEAN

    >
    > #pragma once directs the preprocessor of MS Visual C++ to #include the
    > file only one time per compilation unit, even if more than one
    > #include for the file is encountered. #pragma is the standard way to
    > add non-standard behavior to C++; other compilers will just ignore the
    > line. A better way to achieve the effect would be
    >
    > xyz.h:
    >
    > #ifndef _XYZ_H_INCLUDED
    > #define _XYZ_H_INCLUDED
    > ... /* remainder of file */
    > #endif
    >

    <snip>

    We actually put BOTH #pragma once and the #ifndef syntax into our header
    files.

    #pragma once compiles faster; once the compiler has seen it for a .h
    file, it doesn't even open the file the 2nd time, whereas the other,
    portable, syntax requires the compiler to read the entire file again.
    Even though it only requires very light processing it still takes some time.

    But this is strictly MS only.

    #WIN#@_LEN_AND_MEAN? Never seen it. It sound a bit like the

    #define WIN32_LEAN_AND_MEAN that MS use to minimise bloat (as
    Christopher put it)

    See http://support.microsoft.com/kb/166474

    Andy
    Andy Champ, Mar 27, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacob Jensen

    pragma once

    Jacob Jensen, Apr 3, 2004, in forum: C++
    Replies:
    14
    Views:
    8,525
    Julie
    Apr 5, 2004
  2. Rick

    #pragma once in ISO standard yet?

    Rick, Dec 12, 2007, in forum: C Programming
    Replies:
    33
    Views:
    1,214
    CBFalconer
    Dec 15, 2007
  3. Rick
    Replies:
    4
    Views:
    422
    Pete Becker
    Dec 13, 2007
  4. Subrat
    Replies:
    3
    Views:
    780
    James Kanze
    Jul 2, 2008
  5. Gancy
    Replies:
    4
    Views:
    168
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page