473,405 Members | 2,300 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,405 software developers and data experts.

Reg: #define

#define GOOGLE
int main(void)
{
printf("%d",GOOGLE);
return 0;
}

In the above program ,by default GOOGLE should be assigned to
zero..right?
But when I try to print it it gives an error at printf
statement....Why?
If I remove the comma before the GOOGLE it compiles succesfully..Why
so?

Please explain..

Thank You.

Regards,
Raghu

Apr 11 '07 #1
6 1856
In article <11*********************@n59g2000hsh.googlegroups. com>,
raghu <ra*********@gmail.comwrote:
>#define GOOGLE
int main(void)
{
printf("%d",GOOGLE);
return 0;
}
>In the above program ,by default GOOGLE should be assigned to
zero..right?
No. GOOGLE would only be substituted as 0 in evaluating #if
conditions. Otherwise, it is substituted as nothing at all.
That would make your printf statement into

printf("%d",)

which is a syntax error.
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
Apr 11 '07 #2
"raghu" <ra*********@gmail.comwrites:
#define GOOGLE
int main(void)
{
printf("%d",GOOGLE);
return 0;
}

In the above program ,by default GOOGLE should be assigned to
zero..right?
But when I try to print it it gives an error at printf
statement....Why?
Walter Roberson already answered that.
If I remove the comma before the GOOGLE it compiles succesfully..Why
so?
Without the comma, the line is equivalent to

printf("%d");

which is wrong, but it's not an error that the compiler is required to
detect. With a "%d" format, you need an argument of type int -- but
the compiler doesn't necessarily know that. (Some compilers are
clever enough to warn you about such things.) If you execute the
program, the behavior is undefined.

--
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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 11 '07 #3
On Apr 11, 11:53 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1176317218.306739.29...@n59g2000hsh.googlegroups. com>,

raghu <raghujin...@gmail.comwrote:
#define GOOGLE
int main(void)
{
printf("%d",GOOGLE);
return 0;
}
In the above program ,by default GOOGLE should be assigned to
zero..right?

No. GOOGLE would only be substituted as 0 in evaluating #if
conditions. Otherwise, it is substituted as nothing at all.
That would make your printf statement into

printf("%d",)

which is a syntax error.
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
could u just explain a little more as to how it happens

Apr 11 '07 #4
In article <11**********************@o5g2000hsb.googlegroups. com>,
saki <sa***********@gmail.comwrote:
>On Apr 11, 11:53 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1176317218.306739.29...@n59g2000hsh.googlegroups. com>,
>raghu <raghujin...@gmail.comwrote:
>#define GOOGLE
int main(void)
{
printf("%d",GOOGLE);
return 0;
}
In the above program ,by default GOOGLE should be assigned to
zero..right?
>No. GOOGLE would only be substituted as 0 in evaluating #if
conditions. Otherwise, it is substituted as nothing at all.
Correction: GOOGLE would be substituted as nothing at all
even in #if statements. The implicit substitution of 0 for
identifiers only holds for #if statements when the identifier
has *not* been #define'd .
>That would make your printf statement into
printf("%d",)
which is a syntax error.
>could u just explain a little more as to how it happens
Once you have #define'd something using an "object-like" definition
(that is, there is no parameter list on the #define), then
whereever that macro name occurs that is not in quotes, the
-exact- sequence of characters you #define'd it as will be put
into the line, just as if they had always been there. If you
didn't put in any replacement sequence then there will be nothing
to insert there, and the name will effectively be deleted, as if
you had not written it there at all.

[The above is not quite technically correct in certain cases
involving recursive preprocessing macros, and is not technically
correct in certain cases involving object macros defined using the
# operator, such as #define StringMe(foo) #foo ]

If you have #define'd something, then even if you didn't
specify any replacement text, then any #ifdef preprocessor statement
will know that the macro has been defined, and any use of
the defined() operator on an #if statement will know that the
macro has been defined. For example,

If something has -not- been #define'd, then in any #if statement,
it will be replaced by 0. That does not hold if you have #define'd
it in any way: if you #define'd it, the definition you gave will
be substituted in.

#define GOOGLE
#if defined(GOOGLE)
/* This part -will- be included */
#endif
#ifdef GOOGLE
/* This is the same as above; GOOGLE has been defined so
this part -will- be included */
#endif
#if defined(ROCKS)
/* but ROCKS has not been defined, so this part will -not- be included */
#endif
#if !ELGOOG
/* ELGOOG has not been defined, so it will be replaced by 0. You
then have !0 which is 1 which is true, so the #if will succeed
and this part -will- be included */
#endif
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Apr 11 '07 #5
On 11 Apr, 20:53, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
No. GOOGLE would only be substituted as 0 in evaluating #if
conditions. Otherwise, it is substituted as nothing at all.
No. It is replaced with whitespace.
i+GOOGLE+; becames i+ +; which is a syntax error, not i++;.

Apr 13 '07 #6
ar******@email.it wrote On 04/13/07 07:06,:
On 11 Apr, 20:53, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:

>>No. GOOGLE would only be substituted as 0 in evaluating #if
conditions. Otherwise, it is substituted as nothing at all.


No. It is replaced with whitespace.
i+GOOGLE+; becames i+ +; which is a syntax error, not i++;.
No; it is replaced with nothing at all. The reason
`i+GOOGLE+;' is a syntax error is not because GOOGLE is
replaced by white space (it isn't), but because the input
has already been divided into the preprocessor tokens

i
+
GOOGLE
+
;

before the macro is recognized and replaced.

Describing the preprocessor's actions in terms of text
replacement is tempting and may even make them easier for
a new learner to understand, but the description is wrong
at a fundamental level. The preprocessor operates on the
preprocessor tokens that have already been formed from
source text, not on the source text characters themselves.
Once in a while, the distinction is important, as in

#define YAHOO E+6
double million = 1.YAHOO; /* syntax error */

--
Er*********@acm-dot-org.invalid
Apr 13 '07 #7

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

Similar topics

5
by: Henok Girma | last post by:
Hello Gurus, I wanted to have a very simple, strict regular expression validator for a phone field. the only valid format is (XXX) XXX-XXXX where X is a digit I have the following but it always...
1
by: dixie | last post by:
I have a .reg file that I need to run across a network. Currently, we run it for each logon on the network manually, which is not really working well as there are over a hundred users and they...
11
by: csudha | last post by:
Hi all, Can you please explain me the usage of copy constructor and how do we use it. Give me some example. Regards, Sudha.
7
by: DraguVaso | last post by:
Hi, Does anybody knows how to run a *.reg-file silently on a computer? I need this to do automatic updates of my application without user-interaction. So I don't want the user to be asked a...
1
by: Anurag | last post by:
Hi, I have 2 related questions. DB2 UDB ESE v8.x (8.1 till 8.2 FP2 - all fixpaks included) on AIX 5.4.x _____________________________________________________________________________ (QUESTION 1)...
10
by: Harsh_forC | last post by:
hello folks, here i m inserting d very simple code tat im trying to execute.. but still gettin d same error msg,.." Not enuf memory" #include<stdlib.h> #include<stdio.h> void main(void) {
1
by: sowmi | last post by:
Hi All, I am trying to implement the concept of function pointer in C++. While compiling i got some errors which I couldnt figure out the reason . So,Please let me know what changes should be...
6
by: LeWalrus | last post by:
Hi, I've written a reg exp for capturing a group of numbers from text files in the following format: -1.4326 s < 0.6758 s < 1.4334 s Any of the numbers can be positive or negative and the units...
22
by: sivadhanekula | last post by:
Hello Everyone A quick and direct question: I need a C/C++ program to extract the data from the database and the output should be in CSV "Comma Separated Value" format. Briefly: I will be given a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.