473,796 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pre-processor string replacement

Hi Everyone,

I have the following question regarding string replacement
pre-processor statement,

#define status "23"
#define status "44"

int main()
{
printf("%s\n", status);
}

this works fine and prints 44

where as

#define status "23"
#define status1 status

int main()
{
printf("%s\n", status);
}

prints 23, string replacement occurs on the pre-processor statement
itself, which is not in case 1, why is it so?
Can anyone help me on this?

Jan 14 '07 #1
11 2170
>
#define status "23"
#define status1 status

int main()
{
printf("%s\n", status);
}
Sorry i mean

int main()
{
printf("%s\n", status1);
}

Jan 14 '07 #2
sa*****@yahoo.c o.in wrote:
Hi Everyone,

I have the following question regarding string replacement
pre-processor statement,

#define status "23"
#define status "44"

int main()
{
printf("%s\n", status);
}

this works fine and prints 44

where as

#define status "23"
#define status1 status

int main()
{
printf("%s\n", status);
}

prints 23, string replacement occurs on the pre-processor statement
itself, which is not in case 1, why is it so?
Can anyone help me on this?
What did you expect to see?

--
Ian Collins.
Jan 14 '07 #3


#define status "23"
#define status "44"
What did you expect to see?

--
Ian Collins.
i expect first statement to replace status of second statement with
23, so it would be

#define "23" "43"...

which isn't the case, so i though string replacement never happens in
pre-processor statement, however the second example i pointed proves
that understanding is not correct.

Jan 14 '07 #4
sa*****@yahoo.c o.in wrote:
>
>>#define status "23"
#define status "44"

What did you expect to see?

--
Ian Collins.


i expect first statement to replace status of second statement with
23, so it would be

#define "23" "43"...

which isn't the case, so i though string replacement never happens in
pre-processor statement, however the second example i pointed proves
that understanding is not correct.
I see. In the first example you are redefining status (your compiler
did warn you, didn't it?).

--
Ian Collins.
Jan 14 '07 #5
I see. In the first example you are redefining status (your compiler
did warn you, didn't it?).

--
Ian Collins.
Yes it did, but my question is had the pre-processor replaced status
with "23" compiler wouldn't have known... why did the pre-processor
choose not to replace status of the second #define with "23"

#define status "23"
#define status "44"

Jan 14 '07 #6
sa*****@yahoo.c o.in said:
Hi Everyone,

I have the following question regarding string replacement
pre-processor statement,

#define status "23"
#define status "44"

int main()
{
printf("%s\n", status);
}

this works fine and prints 44
This time, maybe. Next time it might not. Your program exhibits undefined
behaviour. Get the easy stuff right before worrying about the hard stuff.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 14 '07 #7
sa*****@yahoo.c o.in wrote:
>>I see. In the first example you are redefining status (your compiler
did warn you, didn't it?).
Please trim signatures.
>
Yes it did, but my question is had the pre-processor replaced status
with "23" compiler wouldn't have known... why did the pre-processor
choose not to replace status of the second #define with "23"
Because you are redefining the token, not using it. As Richard pointed
out, this is undefined.

Get your code to compile without warnings.

--
Ian Collins.
Jan 14 '07 #8
Ian Collins said:
sa*****@yahoo.c o.in wrote:
>>>I see. In the first example you are redefining status (your compiler
did warn you, didn't it?).
Please trim signatures.
>>
Yes it did, but my question is had the pre-processor replaced status
with "23" compiler wouldn't have known... why did the pre-processor
choose not to replace status of the second #define with "23"
Because you are redefining the token, not using it. As Richard pointed
out, this is undefined.
Actually, what I was referring to was the call to a variadic function
without a valid prototype in scope.
Get your code to compile without warnings.
....after cranking up the warning level to a reasonable height.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 14 '07 #9
On 14 Jan 2007 00:10:18 -0800, in comp.lang.c , sa*****@yahoo.c o.in
wrote:
>
>
#define status "23"
#define status "44"
What did you expect to see?

--
Ian Collins.

i expect first statement to replace status of second statement with
23, so it would be

#define "23" "43"...
No, the preprocessor doesn't work like that. All you've done is
redefine status.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jan 14 '07 #10

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

Similar topics

2
3107
by: GriffithsJ | last post by:
Hi I have been given some text that needs to be displayed on a web page. The text is pre-formatted (includes things like lists etc) and displays okay if I wrap it using the <pre/> tag. However, the font used is rather "naff" and looks too different to the rest of my web page. I'm not sure how I can (or even whether I can) override the font used with the <pre/> tag. If not, is there another tag I can use to display pre-formatted...
7
18537
by: Alan Illeman | last post by:
How do I set several different properties for PRE in a CSS stylesheet, rather than resorting to this: <BODY> <PRE STYLE="font-family:monospace; font-size:0.95em; width:40%; border:red 2px solid; color:red;
2
2790
by: Buck Turgidson | last post by:
I want to have a css with 2 PRE styles, one bold with large font, and another non-bold and smaller font. I am new to CSS (and not exactly an expert in HTML, for that matter). Is there a way to do this in CSS? <STYLE TYPE="text/css"> pre{ font-size:xx-large;
3
12927
by: Michael Shell | last post by:
Greetings, Consider the XHTML document attached at the end of this post. When viewed under Firefox 1.0.5 on Linux, highlighting and pasting (into a text editor) the <pre> tag listing will preserve formatting (white space and line feeds). However, this is not true when doing the same with the <code> tag listing (it will all be pasted on one line with multiple successive spaces treated as a single space) despite the fact that...
8
3804
by: Jarno Suni not | last post by:
It seems to be invalid in HTML 4.01, but valid in XHTML 1.0. Why is there the difference? Can that pose a problem when such a XHTML document is served as text/html?
7
2752
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no tags will remain making the page safe (I have to convert the linefeeds to <BR>s because the Server.EncodeHTML does not do that it seems). The problem is that users can use a special tag when editing the top to specify an area of the tip that will...
9
5551
by: Eric Lindsay | last post by:
I can't figure how to best display little snippets of shell script using <pre>. I just got around to organising to bulk validate some of my web pages, and one of the problems occurs with Bash shell pieces like this: <pre><code> #!/bin/sh ftp -i -n ftp.server.com&lt; &lt;EOF user username password epsv4 cd /
23
3650
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a so-called pre-fix notation or algebraic notation. Algebraic notations have the concept of operators, meaning, symbols placed around arguments. In algebraic in-fix notation, different
14
3633
by: Schraalhans Keukenmeester | last post by:
I am building a default sheet for my linux-related pages. Since many linux users still rely on/prefer viewing textmode and unstyled content I try to stick to the correct html tags to pertain good readibility on browsers w/o css-support. For important notes, warnings etc I use the <pre> tag, which shows in a neat bordered box when viewed with css, and depending on its class a clarifying background-image is shown. I would like the...
0
9685
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, 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...
0
10461
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, 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...
1
10190
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10019
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
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...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
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
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.