Solved

#if _MSC_VER > 1000

Posted on 2001-09-07
7
3,194 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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