Solved

#if _MSC_VER > 1000

Posted on 2001-09-07
7
3,381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 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