Click to See Complete Forum and Search --> : What is #if !defined(AFX_xxxxxxx_INCLUDED_)
frog_jr
April 29th, 2005, 04:00 PM
I have come across several files that have something like:
#if !defined(AFX_STDAFX_H__EA97A192_032A_11D4_A4DA_000000000000__INCLUDED_)
#define AFX_STDAFX_H__EA97A192_032A_11D4_A4DA_000000000000__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
...
#endif // !defined(AFX_STDAFX_H__EA97A192_032A_11D4_A4DA_000000000000__INCLUDED_)
I am assuming this is just a way of insuring that the file is included only once, but was wondering what generated all of the "stuff" inside the parentheses found here?
Also, isn't the
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
redundant when the other is present?
Thanks
Siddhartha
April 29th, 2005, 04:30 PM
I am assuming this is just a way of insuring that the file is included only once... Yes, you are right. :thumb:
Also, isn't the
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
redundant when the other is present? Redundant in some senses and not all.
Whilst both ensure that the following lines are not compiled twice -
#pragma once also ensures that the file is opened for reading only once - and this reduces compile time.
#pragma once is a MSVC compiler specific feature introduced after version 1000, and hence the version check.
frog_jr
April 29th, 2005, 06:36 PM
#pragma once also ensures that the file is opened for reading only once - and this reduces compile time.
#pragma once is a MSVC compiler specific feature introduced after version 1000, and hence the version check.
AHA! Duh! Of course!
Now, my query is is there a tool that generates the code in the "defined" parameters or is this just a convention that some programmers use?
Do the numbers have a (understandable) meaning?
I'm wondering if there is a "feature" of msVC that can do this for me?
Siddhartha
April 30th, 2005, 04:14 AM
Now, my query is is there a tool that generates the code in the "defined" parameters or is this just a convention that some programmers use?
Do the numbers have a (understandable) meaning? They have no meaning - they follow a naming convention.
I'm wondering if there is a "feature" of msVC that can do this for me? If you add a class via the Add Class wizard, MSVC will do it (the multiple inclusion protection) for your new class automatically.
miteshpandey
May 1st, 2005, 12:33 PM
Just curious.
Does the parameter has something to do with uniqueness.? Like a GUID?
Siddhartha
May 1st, 2005, 03:40 PM
Does the parameter has something to do with uniqueness.? Like a GUID? Yes, in
#ifndef MYMACRO that guards against multiple inclusions, MYMACRO has to be unique per project
Else, it will block the content of the other header(s) that duplicate define it from being compiled. ;)
However, unlike a GUID, this has to be unique on a project basis only.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.