What is #pragma once used for

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raashid bhatt

    What is #pragma once used for

    What is #pragma once used for
    and
    what is #WIN#@_LEN_AND_ MEAN
  • Michael.Boehnisch@gmail.com

    #2
    Re: What is #pragma once used for

    On 27 Mrz., 06:12, raashid bhatt <raashidbh...@g mail.comwrote:
    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_ME AN preprocessor symbol in MS
    Visual C++ excludes rarely used stuff from the platform specific
    #include files (windows.h, ...).

    best,

    Michael

    Comment

    • James Kanze

      #3
      Re: What is #pragma once used for

      On Mar 27, 6:12 am, raashid bhatt <raashidbh...@g mail.comwrote:
      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:james.kan ze@gmail.com
      Conseils en informatique orientée objet/
      Beratung in objektorientier ter Datenverarbeitu ng
      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

      Comment

      • Krice

        #4
        Re: What is #pragma once used for

        On 27 maalis, 11:36, James Kanze <james.ka...@gm ail.comwrote:
        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.

        Comment

        • James Kanze

          #5
          Re: What is #pragma once used for

          On Mar 27, 11:34 am, Krice <pau...@mbnet.f iwrote:
          On 27 maalis, 11:36, James Kanze <james.ka...@gm ail.comwrote:
          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:james.kan ze@gmail.com
          Conseils en informatique orientée objet/
          Beratung in objektorientier ter Datenverarbeitu ng
          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

          Comment

          • Andy Champ

            #6
            OT: Re: What is #pragma once used for

            Michael.Boehnis ch@gmail.com wrote:
            On 27 Mrz., 06:12, raashid bhatt <raashidbh...@g mail.comwrote:
            >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

            Comment

            Working...