Is there any standard for when to use #if
!defined(SOME_I NCLUSION_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? 4 9754
"Evan" <ee****@psu.edu > wrote in message
news:3f******** *************** ***@posting.goo gle.com... Is there any standard for when to use #if !defined(SOME_I NCLUSION_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
Evan wrote: Is there any standard for when to use #if !defined(SOME_I NCLUSION_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
"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?
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
ifndef/define directives, the code between the statements
define and endif was only compiled once. But this seems
to be incorrect, as I get a whole bunch of errors when
I compile the critter.
For example if I include header.h more than once the
|
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
|
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 links by using
#ifndef
|
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__ Uint32 MD2SwapInt(Uint32 D) {
|
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
....
#endif
Yet when I build my program, the DJGPP compiler tells me there are multiple
definitions of each of my functions.
| |
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 an
explanation ????
Thanks
Ahmed.
|
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 statement in my own program?
Thank you so much!
|
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
etc...
|
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 DATE_TIME unsigned long
#endif // NOT DATE_TIME
The #define DATE_TIME I am handling with:
public const UInt32 DATE_TIME;
|
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_*/
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |