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

##-concatenation

Hi,

Why is this code not working ?
It says " 'TestFn_this_is_new_string' : undeclared identifier"

#define NEW_STR(x) {x##_this_is_new_string }

struct command
{
char *name;
}cm[10] = {NEW_STR(testFn)} ;
Thx,
Ravi
Nov 14 '05 #1
3 1559
Ravi Uday <ra*****@yahoo.com> scribbled the following:
Hi, Why is this code not working ?
It says " 'TestFn_this_is_new_string' : undeclared identifier" #define NEW_STR(x) {x##_this_is_new_string } struct command
{
char *name;
}cm[10] = {NEW_STR(testFn)} ;


Perhaps because you haven't declared the variable
TestFn_this_is_new_string anywhere?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Holy Banana of this, Sacred Coconut of that, Magic Axolotl of the other."
- Guardian in "Jinxter"
Nov 14 '05 #2
Ravi Uday <ra*****@yahoo.com> spoke thus:
Why is this code not working ?
It says " 'TestFn_this_is_new_string' : undeclared identifier" #define NEW_STR(x) {x##_this_is_new_string } struct command
{
char *name;
}cm[10] = {NEW_STR(testFn)} ;


Well, after the macro substitution, you get

struct command
{
char *name;
} cm[10] = {testFn_this_is_new_string} ;

First, note that the error message you posted has a capital T, while
the string you're using for the macro argument has a lowercase t. C
is case-sensitive, so that could be your problem right there. If not,
it's probably as Joona suggested - you just didn't declare this
oddly-named variable anywhere.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #3
Ravi Uday a écrit :
Why is this code not working ?
It says " 'TestFn_this_is_new_string' : undeclared identifier"

#define NEW_STR(x) {x##_this_is_new_string }
I think you want this instead:

#define NEW_STR(x) {#x "_this_is_new_string" }

The following points can explain why the above code works, but not yours:
- You forgot the quotes to make a valid literal string.
- You did not use the '#' to turn an identifier into a literal string.
- Consecutive literal strings are automatically concatenated, so you do
not need the ## macro operator.
struct command
{
char *name;
}cm[10] = {NEW_STR(testFn)} ;


--
Richard
Nov 14 '05 #4

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

Similar topics

7
by: Oliver Crow | last post by:
As a realtive python newb, but an old hack in general, I've been interested in the impact of having string objects (and other primitives) be immutable. It seems to me that string concatenation is...
5
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?
1
by: Fahd Khan | last post by:
Hi team! While troubleshooting a crash I had while using BitTorrent where the torrent's target file names didn't fall into the ascii range I was playing around in the interpreter and noticed this...
1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
8
by: mrstephengross | last post by:
I'm using gcc 3.3.1 to compile the following code (below). I've written a macro to simplify writing operators. The macro uses the '##' operator to paste together 'operator' and the name of the...
9
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...
33
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...
34
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. ...
34
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
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,...
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
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...

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.