Solved

#if _MSC_VER > 1000

Posted on 2001-09-07
7
3,230 Views
Last Modified: 2013-11-20
what exactly is this statement used for
#if _MSC_VER > 1000
#pragma once
#endif
0
Comment
Question by:mjh2
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6464814
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:



0
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
ID: 6465898
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:

#if !defined(DLGPGSVRPARSING_H)
#define DLGPGSVRPARSING_H
... entire source file here ...
#endif

Therefore, if you expect to always use VC++ 6.0 or later, you could manually replace this ugly baggage at the top of your .h files:
---==-=--==--=-=-=-=-=-==--=-=
#if !defined(AFX_DLGPGSVRPARSING_H__B25B9214_2E48_46EB_A306_F750626C5256__INCLUDED_)
#define AFX_DLGPGSVRPARSING_H__B25B9214_2E48_46EB_A306_F750626C5256__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
---==-=--==--=-=-=-=-=-==--=-=
with this one, clean line:

#pragma once

Just remember to also delete the #endif line tha tlooks like this from the bottom of the file:
---==-=--==--=-=-=-=-=-==--=-=
#endif // !defined(AFX_DLGPGSVRPARSING_H__B25B9214_2E48_46EB_A306_F750626C5256__INCLUDED_)
---==-=--==--=-=-=-=-=-==--=-=

-- Dan
0
 
LVL 86

Expert Comment

by:jkr
ID: 6466004
>>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)

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:jkr
ID: 6468695
???
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6469592
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 6472005
>>I had no intention of 'poaching'

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

Author Comment

by:mjh2
ID: 6477437
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 53
countEvens challenge 2 75
fix34  challenge 9 104
scoreUp challenge 14 57
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now