Re: if !defined and #pragma once

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Ajay Kalra wrote:
On Apr 1, 6:18 am, asm23 <asmwarr...@xxxxxxxxx> wrote:
Hi,I'm a visual c++ 6.0 user. I'm confused that the CPP file generated
by the IDE always have these statement below:

#if!defined(AFX_XXXXX_H__32583F3A_E701_4274_AFD6_426BC1C59E81__INCLUDED_)
#define AFX_XXXXX_H__32583F3A_E701_4274_AFD6_426BC1C59E81__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

So, my question is "#if! defined (XXXX...)" is really useless? as the
newer compiler such as VS.NET 2001 VC.NET 2003...2008 all support the
#pragma once. the "if! ..." is functionally redundant.Is it right? Thanks.


Just use #pragma once instead. Since this pragma was added in VC6,
anything before that will not recognize. So for code for VC5 etc, this
was kept in VC6. It no longer is an issue and I only use #pragma once.


Ajay:

VC5 was _MSC_VER = 1100. "#pragma once" was in the wizard code in VC5.

--
David Wilkinson
Visual C++ MVP
.



Relevant Pages

  • Re: if !defined and #pragma once
    ... #pragma once ... newer compiler such as VS.NET 2001 VC.NET 2003...2008 all support the ... introduced in VC6. ... I hardly used VC5. ...
    (microsoft.public.vc.mfc)
  • Re: Confusing #ifdef
    ... uses #pragma once so far as I can see. ... to VC6. ... don't use the save value in anyother header file in your project. ...
    (microsoft.public.vc.mfc)
  • Re: if !defined and #pragma once
    ... Not true, of course, but still sounds funny. ... "David Wilkinson" wrote in message ... #pragma once ... Since this pragma was added in VC6, ...
    (microsoft.public.vc.mfc)
  • Re: if !defined and #pragma once
    ... #pragma once ... defined " is really useless? ... newer compiler such as VS.NET 2001 VC.NET 2003...2008 all support the ... Since this pragma was added in VC6, ...
    (microsoft.public.vc.mfc)
  • Re: if !defined and #pragma once
    ... VC5 Yikes, I hope no one is using anything that old... ... "Ajay Kalra" wrote in message ... #pragma once ... Since this pragma was added in VC6, ...
    (microsoft.public.vc.mfc)