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

C preprocessor problem

Hi all,

I'm trying to generate a static string from two defines that are
passed in on the command line during make (via -D). I'll admit that my
understanding of the C preprocessor is not great ,and I can't work out
how to join the two together at compile time. At the moment I've tried

static const U8BIT *app_sw_ver_no_str =
(U8BIT*)#APP_VERSION_STRING##APP_DATE_STRING

But this fails with gcc. Could anybody tell me how I can join the two
defines into a string?

Thanks,
Gaz.

Nov 12 '07 #1
4 1692
gp******@gmail.com said:
Hi all,

I'm trying to generate a static string from two defines that are
passed in on the command line during make (via -D). I'll admit that my
understanding of the C preprocessor is not great ,and I can't work out
how to join the two together at compile time. At the moment I've tried

static const U8BIT *app_sw_ver_no_str =
(U8BIT*)#APP_VERSION_STRING##APP_DATE_STRING

But this fails with gcc. Could anybody tell me how I can join the two
defines into a string?
http://c-faq.com/ansi/stringize.html

Note especially the sentence beginning "Note that both # and ## operate
only..."

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 12 '07 #2

gpear...@gmail.com wrote:
Hi all,

I'm trying to generate a static string from two defines that are
passed in on the command line during make (via -D). I'll admit that my
understanding of the C preprocessor is not great ,and I can't work out
how to join the two together at compile time. At the moment I've tried

static const U8BIT *app_sw_ver_no_str =
(U8BIT*)#APP_VERSION_STRING##APP_DATE_STRING

But this fails with gcc. Could anybody tell me how I can join the two
defines into a string?
C automatically merges adjacent string literals separated only by
whitespace. Thus, "Hello, " "world!" is essentially the same as as
"Hello, world!". Therefore, it's actually much simpler than think.
All you have to do is:

static const U8BIT *app_sw_ver_no_str =
(U8BIT*) APP_VERSION_STRING APP_DATE_STRING;

Note: the # and ## operators are useful only within the replacement
list for the #define of a function-like macro.

Nov 12 '07 #3
On Nov 13, 11:49 am, jameskuy...@verizon.net wrote:
gpear...@gmail.com wrote:
Hi all,
I'm trying to generate a static string from two defines that are
passed in on the command line during make (via -D).

All you have to do is:

static const U8BIT *app_sw_ver_no_str =
(U8BIT*) APP_VERSION_STRING APP_DATE_STRING;
That assumes that the defines include quotes already,
e.g. -DAPP_VERSION_STRING="foo" . If not, then the OP
will have to use a stringize macro as well, e.g.

static const U8BIT *app_sw_ver_no_str = (U8BIT*)
STRINGIZE(APP_VERSION_STRING) STRINGIZE(APP_DATE_STRING);
Nov 12 '07 #4

Old Wolf wrote:
On Nov 13, 11:49 am, jameskuy...@verizon.net wrote:
gpear...@gmail.com wrote:
Hi all,
I'm trying to generate a static string from two defines that are
passed in on the command line during make (via -D).
All you have to do is:

static const U8BIT *app_sw_ver_no_str =
(U8BIT*) APP_VERSION_STRING APP_DATE_STRING;

That assumes that the defines include quotes already,
It figured that two macros both named with a _STRING suffix, intended
for use in C code, would have values that already had double quotes
around them. Still, I suppose it is possible.

Nov 12 '07 #5

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

Similar topics

205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
24
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was...
9
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour....
2
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0...
25
by: Gernot Frisch | last post by:
Hi, I want to build a encryption macro set, that can crypt: char secret = CRYPT("KungFu"); to anything unreadable, and then have a function: char* DECRYPT(char* str) { ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.