473,397 Members | 1,950 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,397 software developers and data experts.

new to c #define

Hello,
I am modifying some code and there is a #define with no value. It looks
like its used for testing.There are several #ifdef references.Is this
ignored if there is no value assigned?
Thanks
Mike

Sep 8 '06 #1
5 1982
In article <11*********************@e3g2000cwe.googlegroups.c om>,
<am******@gmail.comwrote:
>I am modifying some code and there is a #define with no value. It looks
like its used for testing.There are several #ifdef references.Is this
ignored if there is no value assigned?
No, a #define with no value defines the value as 0 but marks it as
defined.

Be careful using the variable in preprocessor expressions:

#define FOO
#define BAR 1
/* BAZ is not defined at all */

then taking each of the below individually:
#ifdef FOO /* this is true */

#ifdef BAR /* this is true */

#ifdef BAZ /* this is false */

#if FOO /* this is false because FOO's value 0 is substituted */

#if BAR /* this is true because BAR's value 1 is substituted */

#if BAZ /* this is false because all symbols remaining after
preprocessing have 0 substituted for them, so
0 is put in in place of BAZ */

#if defined(FOO) /* this is true */

#if defined(BAR) /* this is true */

#if defined(BAZ) /* this is false */

#if !FOO /* this is true because FOO is 0 and !0 is true */

#if !BAR /* this is false because BAR is 1 and !1 is false */

#if !BAZ /* this is true because remaining symbols have 0
substituted for them, making this !0 which is true */
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
Sep 8 '06 #2


am******@gmail.com wrote On 09/08/06 12:28,:
Hello,
I am modifying some code and there is a #define with no value. It looks
like its used for testing.There are several #ifdef references.Is this
ignored if there is no value assigned?
The macro is defined, but with an empty value. If
you use the macro somewhere, it will be replaced by its
expansion, which is empty -- in effect, the macro just
disappears.

However, even though the macro's value is empty, the
macro is defined. Since #ifdef and #if defined ... and
#ifndef test the defined/undefined status and not the
value, they will all "see" the macro.

--
Er*********@sun.com

Sep 8 '06 #3
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <11*********************@e3g2000cwe.googlegroups.c om>,
<am******@gmail.comwrote:
>>I am modifying some code and there is a #define with no value. It looks
like its used for testing.There are several #ifdef references.Is this
ignored if there is no value assigned?

No, a #define with no value defines the value as 0 but marks it as
defined.
No, it expands to an empty sequence of tokens.

Given "#define FOO", the directive "#if FOO" is illegal.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 8 '06 #4
am******@gmail.com wrote:
>
I am modifying some code and there is a #define with no value. It
looks like its used for testing.There are several #ifdef references.Is
this ignored if there is no value assigned?
What kind of a file or record field is "testing.There", and
"references.Is"?

--
"The smaller aperture of the lid has been designed to prevent
hedgehogs from entering the McFlurry container in the
unfortunate incidence that the lid is littered"
-- McDonalds, as quoted in Time, 2006-09-11

Sep 8 '06 #5


CBFalconer wrote On 09/08/06 16:06,:
am******@gmail.com wrote:
>>I am modifying some code and there is a #define with no value. It
looks like its used for testing.There are several #ifdef references.Is
this ignored if there is no value assigned?


What kind of a file or record field is "testing.There", and
"references.Is"?
Pedant traps.

--
Er*********@sun.com

Sep 8 '06 #6

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

Similar topics

18
by: Bryan Parkoff | last post by:
"#define" can only be inside the global scope before main() function. "#if" can be tested after "#define" is executed. The problem is that "#define" can't be inside main() function. I do not wish...
2
by: Andreas | last post by:
Hi! I'm using an IplImage library from camellia.sourceforge.net, and the testbench calls a file only containing code like the one below. In cam_morphomaths_code.c the real computation is made,...
3
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
9
by: pozz | last post by:
Hi all, I have the below #defines #define NUMBER1 30 #define NUMBER2 50 #define SUM (NUMBER1+NUMBER2) #define STRING1 "Byte: \x30" #define STRING2 "Byte: \x50"...
34
by: BQ | last post by:
Hello Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20. I would like that at compile time, not at run time. ...
17
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
71
by: David T. Ashley | last post by:
Where is the best place to define TRUE and FALSE? Are they in any of the standard include files, ever? Do any standards apply? What I've traditionally done is something like: #ifndef...
6
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
23
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
2
by: badc0de | last post by:
Hello.. a header file of one of my project has macro definitions like this (for example) #define PART_A_SORT_1_LABEL_STRING1 100 #define PART_A_SORT_1_LABEL_STRING2 200 #define...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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
jinu1996
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...
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...

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.