What is #pragma once used for

C

Christopher Pisz

raashid bhatt said:
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.
 
M

Michael.Boehnisch

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
 
A

Andrey Tarasevich

raashid said:
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.
 
K

Krice

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.
 
J

James Kanze

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.)
 
A

Andy Champ

#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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top