473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

#if !defined() vs #ifndef

Is there any standard for when to use #if
!defined(SOME_INCLUSION_GUARD) versus #ifndef SOME_INCLUSION_GUARD?

Aside from being able to combine multiple things into an #if, is there
any difference? My VC++ docs say that thay are equivalent, but is
there any convention on when to use one vs. another?

Also, how widely is #pragma once supported?
Jul 19 '05 #1
4 9707

"Evan" <ee****@psu.edu> wrote in message
news:3f**************************@posting.google.c om...
Is there any standard for when to use #if
!defined(SOME_INCLUSION_GUARD) versus #ifndef SOME_INCLUSION_GUARD?

Aside from being able to combine multiple things into an #if, is there
any difference? My VC++ docs say that thay are equivalent, but is
there any convention on when to use one vs. another?

Also, how widely is #pragma once supported?

I think #pragma is designed to allow compiler vendors to provide their own
preprocessor extension (MS VC++ offers things like pack and others). Hence
it will vary across different compilers/platforms.
HTH,
S. Armondi
Jul 19 '05 #2
Evan wrote:
Is there any standard for when to use #if
!defined(SOME_INCLUSION_GUARD) versus #ifndef SOME_INCLUSION_GUARD?
Both are perfectly fine in Standard C++,

However, if you are actually writing an inclusion guard or
similar which defines a macro immediately afterwards, an
#ifndef and a #define on the subsequent line, match up quite
nicely, as you can see:

#ifndef A
#define A
....
#endif

It's just a matter of preference, style or coding standards.
Also, how widely is #pragma once supported?


What a #pragma does is entirely up to a compiler, and an
unknown #pragma is ignored. So it's "supported" everywhere,
but only causes the specific behavior you have in mind
on those compilers for which you know for certain that it
causes that specific behavior.

S

Jul 19 '05 #3
TR
"Scott Condit" <so****@socode.com> wrote in message
news:be************@ID-189137.news.uni-berlin.de...
Also, how widely is #pragma once supported?


What a #pragma does is entirely up to a compiler, and an
unknown #pragma is ignored. So it's "supported" everywhere,
but only causes the specific behavior you have in mind
on those compilers for which you know for certain that it
causes that specific behavior.


Satisfying knowing you've helped someone out, isn't it?
Jul 19 '05 #4
TR wrote:
"Scott Condit" <so****@socode.com> wrote in message
news:be************@ID-189137.news.uni-berlin.de...
Better to tell how it is than how someone would like it
to be, isn't it?

He clearly knows pragma once isn't defined by the standard,
but that wasn't his question.


But might have thought its behavior would be the same on any
system that appeared to accept it. See below.
If you don't know the answer, you're sometimes better not
saying anything.


Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: prettysmurfed | last post by:
Hi all I have this, probably stupid question, how to avoid multiple definitions when a header file is included more than once. I thought, when you wrote the header-file and used the...
6
by: Peng Yu | last post by:
I want to define a macro #define FILEWR(FILENAME) which can be expanded to #ifndef OUTFILE #define OUTFILE ofstream out; #endif
1
by: learner | last post by:
Hi, Is there anyth like #ifndef variable in javascript? I want to declare a varibale in a global file. This file is included in all links. I want to keep the variable value visible across...
3
by: Michael Sgier | last post by:
Hello I get the error below. But why and what does ifndef? Well what is ifndef? Many thanks and regards Michael error: syntax error before `(' token #ifndef MD2SwapInt static __inline__...
25
by: John Hanley | last post by:
I have a program where both my main.c and program.c files use the program.h file. So I #include "program.h" in both the .c files. The program.h file has #ifndef PROGRAM_H #define PROGRAM_H...
2
by: S. Md. Kabeer Ahmed | last post by:
There are #ifndef _FILENAME_H used in header files and I very well understand their usage. But I dont know what's the exact use when #ifndef _FILENAME_C is used for c files. can anyone provide me...
9
by: Qiao Jian | last post by:
I am new to c. Today I just read an h file within which there is statements: #ifndef _RANDOM_H #define _RANDOM_H So what is the meaning or purpose of this statement? When should I use such...
5
by: vfunc | last post by:
Despite a #ifndef I am getting a redefinition error The offending .h file looks like the following #ifndef DISTRIB_H #define DISTRIB_H double dblpi; // this is getting compiled twice ...
6
by: canoewhiteh2o | last post by:
I am converting a couple of C header files to C#. It is mainly just a bunch C structs but I am not sure how to handle the #ifdef and #ifndef in C#. For example: #ifndef DATE_TIME #define...
6
by: Johs | last post by:
Each time I make a new .h file in eclipse it starts with this: #ifndef FUNCS_H_ #define FUNCS_H_ // here goes all the code #endif /*FUNCS_H_*/
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.