Link to home
Start Free TrialLog in
Avatar of mjh2
mjh2

asked on

#if _MSC_VER > 1000

what exactly is this statement used for
#if _MSC_VER > 1000
#pragma once
#endif
Avatar of jkr
jkr
Flag of Germany image

This statement is used to differentiate between different compiler versions. From the docs:

_MSC_VER

Defines the compiler version. Defined as 1200 for Microsoft Visual C++ 6.0. Always defined.


This means - in your example - that the code enclosed will only be 'seen' by MS compilers that have an internal version stamp > 1000, as '#pragma once' is probably not implemented by earlier versions. 'once' itself means:

#pragma once

Specifies that the file, in which the pragma resides, will be included (opened) only once by the compiler in a build. A common use for this pragma is the following:

//header.h
#pragma once
// Your C or C++ code would follow:



ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>I might add that '#pragma once'can be used as a
>>replacement for the common practice of placing #ifdef
>>like this at the top and bottom of a header file..

You're right, but I would not recommend abandoning that practise - there are more compilers out than just VC++, even though MFC is focused a little on that compiler implementation (even though I remember that my first encounter with MFC was with Watcom 10.0)

???
hi mjh2,
Thanks for accepting my comment as an answer.  However, in this case, all I did was add a note to an already correct and complete answer that had been given by jkr.

The 'B' grade that you awarded to me, should instead be awarded to jkr.

hi jkr,
sorry.  I had no intention of 'poaching'.

-- Dan
>>I had no intention of 'poaching'

I know - you wrote 'I might add that...'. Well, let's see what mjh22 has to say...
Avatar of mjh2
mjh2

ASKER

I am sorry jkr.. DanRollins answer gave me more insight on what the code is used for. You gave the definition that anyone can find on Microsoft's web page.