Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What is #pragma once used for

Reply
Thread Tools

What is #pragma once used for

 
 
raashid bhatt
Guest
Posts: n/a
 
      03-27-2008
What is #pragma once used for
and
what is #WIN#@_LEN_AND_MEAN
 
Reply With Quote
 
 
 
 
Christopher Pisz
Guest
Posts: n/a
 
      03-27-2008

"raashid bhatt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
 
Michael.Boehnisch@gmail.com
Guest
Posts: n/a
 
      03-27-2008
On 27 Mrz., 06:12, raashid bhatt <(E-Mail Removed)> 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
 
Reply With Quote
 
Andrey Tarasevich
Guest
Posts: n/a
 
      03-27-2008
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
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      03-27-2008
On Mar 27, 6:12 am, raashid bhatt <(E-Mail Removed)> 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:(E-Mail Removed)
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

 
Reply With Quote
 
Krice
Guest
Posts: n/a
 
      03-27-2008
On 27 maalis, 11:36, James Kanze <(E-Mail Removed)> 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.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      03-27-2008
On Mar 27, 11:34 am, Krice <(E-Mail Removed)> wrote:
> On 27 maalis, 11:36, James Kanze <(E-Mail Removed)> 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:(E-Mail Removed)
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
 
Reply With Quote
 
Andy Champ
Guest
Posts: n/a
 
      03-27-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On 27 Mrz., 06:12, raashid bhatt <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Control with popup used more than once per page does not work lds ASP .Net 0 10-23-2007 02:27 PM
How to prevent query string values from being used more than once? keithb ASP .Net 4 04-08-2006 12:25 AM
ID's only used once? mfunkmann@yahoo.com HTML 1 03-21-2006 06:28 PM
stringstream used to convert int to string does work only once? Field C++ 3 06-17-2005 01:53 AM
Regex to match say char 't' exactly once in a string and no more than once Gancy Perl Misc 4 02-03-2005 02:19 PM



Advertisments