#include <stdio.h>
#define MYSTR "World"
void foo(char *p)
{
puts(p);
}
int main()
{
foo("Hello" MYSTR);
}
Is this guaranteed to print HelloWorld - it does so on my system,
but just wanted to check.
Basically I wanted to know how to pass a concat of 2 strings, one
of which is in a macro into a function. 8 2306
Pan said:
#include <stdio.h>
#define MYSTR "World"
void foo(char *p)
{
puts(p);
}
int main()
{
foo("Hello" MYSTR);
}
Is this guaranteed to print HelloWorld - it does so on my system,
but just wanted to check.
Yes (and a newline).
Basically I wanted to know how to pass a concat of 2 strings, one
of which is in a macro into a function.
Two string literals, yes. Whether one or the other or neither or both is
a macro is neither here nor there, but they must both be string
literals if you want the preprocessor to glue them together for you.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:sq******************************@bt.com...
Pan said:
>#include <stdio.h> #define MYSTR "World"
void foo(char *p) { puts(p); }
int main() { foo("Hello" MYSTR); }
Is this guaranteed to print HelloWorld - it does so on my system, but just wanted to check.
Yes (and a newline).
>Basically I wanted to know how to pass a concat of 2 strings, one of which is in a macro into a function.
Two string literals, yes. Whether one or the other or neither or both is
a macro is neither here nor there, but they must both be string
literals if you want the preprocessor to glue them together for you.
Thank you, Richard.
I assume this would work for more than 2 also
i.e.
foo("Hello" MYSTR "Goodbye");
Pan said:
<snip>
I assume this would work for more than 2 also
i.e.
foo("Hello" MYSTR "Goodbye");
puts("Yes, that's"
" right, you"
" can glue t"
"ogether as "
"many as you"
" like (with"
"in reason).");
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Richard Heathfield wrote:
Pan said:
<snip>
>I assume this would work for more than 2 also i.e.
foo("Hello" MYSTR "Goodbye");
puts("Yes, that's"
" right, you"
" can glue t"
"ogether as "
"many as you"
" like (with"
"in reason).");
Where "in reason" translates to about 500 chars. It is specified
in the standard somewhere.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
In article <46***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
>Where "in reason" translates to about 500 chars. It is specified in the standard somewhere.
Just before the limit of 32767 bytes in an object.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
"Richard Heathfield" <rj*@see.sig.invalida écrit dans le message de news: sq******************************@bt.com...
Pan said:
>#include <stdio.h> #define MYSTR "World"
void foo(char *p) { puts(p); }
int main() { foo("Hello" MYSTR); }
Is this guaranteed to print HelloWorld - it does so on my system, but just wanted to check.
Yes (and a newline).
>Basically I wanted to know how to pass a concat of 2 strings, one of which is in a macro into a function.
Two string literals, yes. Whether one or the other or neither or both is
a macro is neither here nor there, but they must both be string
literals if you want the preprocessor to glue them together for you.
This is a late reply, but contrary to popular belief, it is not the
preprocessor that glues adjacent string literals together, but the compiler
in translation phase 6 (6.4.5p4).
--
Chqrlie.
Charlie Gordon said:
"Richard Heathfield" <rj*@see.sig.invalida écrit dans le message de
news: sq******************************@bt.com...
<snip>
>> Two string literals, yes. Whether one or the other or neither or both is a macro is neither here nor there, but they must both be string literals if you want the preprocessor to glue them together for you.
This is a late reply, but contrary to popular belief, it is not the
preprocessor that glues adjacent string literals together, but the
compiler in translation phase 6 (6.4.5p4).
It's the implementation, in fact: and phase 6 comes *before* translation
(which happens in TP7), so it's still *pre*-processing. I have read
6.4.5(4) and failed to find any mention of a compiler.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
"Richard Heathfield" <rj*@see.sig.invalida écrit dans le message de news: eJ******************************@bt.com...
Charlie Gordon said:
>"Richard Heathfield" <rj*@see.sig.invalida écrit dans le message de news: sq******************************@bt.com...
<snip>
>>> Two string literals, yes. Whether one or the other or neither or both is a macro is neither here nor there, but they must both be string literals if you want the preprocessor to glue them together for you.
This is a late reply, but contrary to popular belief, it is not the preprocessor that glues adjacent string literals together, but the compiler in translation phase 6 (6.4.5p4).
It's the implementation, in fact: and phase 6 comes *before* translation
(which happens in TP7), so it's still *pre*-processing. I have read
6.4.5(4) and failed to find any mention of a compiler.
All C preprocessors I have tested leave the adjacent strings intact. It
does not prove my point beyond common sense understanding of the split
between "preprocessing" and "compiling".
Translation phases are described in c99 5.1.1.2: it is clear that
translation phase 4 is included in the "preprocessing". Translation phase 5
would have to be reverted for "preprocessing output" to be produced. I
think it implies that "preprocessing" covers phases 1 through 4, but
excludes phases 5 and 6, but it would not break much to include them and go
through extra work to produce parsable output where adjacent string literals
have been concatenated. It is just not what compiler writers seem to
choose.
--
Chqrlie. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jonas Galvez |
last post by:
Is it true that joining the string elements of a list is faster than
concatenating them via the '+' operator?
"".join()
vs
'a'+'b'+'c'
If so, can anyone explain why?
|
by: hagai26 |
last post by:
I am looking for the best and efficient way to replace the first word
in a str, like this:
"aa to become" -> "/aa/ to become"
I know I can use spilt and than join them
but I can also use regular...
|
by: John Ford |
last post by:
For simple string concatenation, is there a difference between...
Dim s As String
s += "add this to string"
....and...
Dim s As String
s = String.Concat(s, "add this to string")
|
by: Justin M. Keyes |
last post by:
Hi,
Please read carefully before assuming that this is the same old
question about string concatenation in C#!
It is well-known that the following concatenation produces multiple
immutable...
|
by: Mark A. Sam |
last post by:
Hello,
I am having a problem with imputting into a string variable:
Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower,...
|
by: genc_ymeri |
last post by:
Hi over there,
Propably this subject is discussed over and over several times. I did google
it too but I was a little bit surprised what I read on internet when it
comes 'when to use what'.
Most...
|
by: Richard Lewis Haggard |
last post by:
I thought that the whole point of StringBuilder was that it was supposed to
be a faster way of building strings than string. However, I just put
together a simple little application to do a...
|
by: Larry Hastings |
last post by:
This is such a long posting that I've broken it out into sections.
Note that while developing this patch I discovered a Subtle Bug
in CPython, which I have discussed in its own section below.
...
|
by: =?Utf-8?B?RWxlbmE=?= |
last post by:
I am surprised to discover that c# automatically converts an integer to a
string when concatenating with the "+" operator. I thought c# was supposed
to be very strict about types. Doesn't it seem...
|
by: raylopez99 |
last post by:
StringBuilder better and faster than string for adding many strings.
Look at the below. It's amazing how much faster StringBuilder is than
string.
The last loop below is telling: for adding...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |