Re: if !defined and #pragma once
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 01 Apr 2008 10:35:20 -0500
The #if !defined() sequence is what is called an "include guard" and was, for decades, the
standard Best Practice to allow you to create header files that could be included multiple
times.
The only problem was that it was inefficient. With VS6, Microsoft added the #pragma once
construct, but since code had to be compiled with older compilers (VS4.2, VS5), the older
include-guards had to remain in place.
Starting with VS.NET, this older support was dropped, and newer wizards only put in the
#pragma once. If you have code that needs to be shared across platforms, however, you
will want to use include-guards as well (this generally applies to, say, math, image, or
signal-processing code that might run on the Mac, Unix, Linux, etc. as well). Otherwise,
as you observe, they are redundant.
joe
On Tue, 01 Apr 2008 18:18:36 +0800, asm23 <asmwarrior@xxxxxxxxx> wrote:
Hi,I'm a visual c++ 6.0 user. I'm confused that the CPP file generatedJoseph M. Newcomer [MVP]
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.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Prev by Date: Re: a question abot whether CComVariant automatically frees its string contents ?
- Next by Date: Re: Serialization
- Previous by thread: Re: if !defined and #pragma once
- Next by thread: Re: if !defined and #pragma once
- Index(es):
Relevant Pages
|