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

macros: not a valid preprocessing token

Hi all

We have a strange problem with macros:

#define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[ ##Tbl##_##Fld]=i##Tbl##_##Fld;

SQLST_MAP_IND_I(RAGREEJ1,FORMFROMTMSTP);

=> gcc 3.3.4 gives the following error:
source.c:173:40: pasting "[" and "RAGREEJ1" does not give a valid
preprocessing token
The same code compiles fine on Win32 (MSVC 7.1) and on z/OS

So what is wrong? The code or... the precompiler?

Bye
Chris
Nov 14 '05 #1
5 8516
Chris wrote:
Hi all

We have a strange problem with macros:

#define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[ ##Tbl##_##Fld]=i##Tbl##_##Fld;

SQLST_MAP_IND_I(RAGREEJ1,FORMFROMTMSTP);

=> gcc 3.3.4 gives the following error:
source.c:173:40: pasting "[" and "RAGREEJ1" does not give a valid
preprocessing token
The same code compiles fine on Win32 (MSVC 7.1) and on z/OS

So what is wrong? The code or... the precompiler?


Try: #define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[Tbl##_##Fld]=i##Tbl##_##Fld
Nov 14 '05 #2
"Chris" <ch*********@spam.com> wrote:
# Hi all
#
# We have a strange problem with macros:
#
# #define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[ ##Tbl##_##Fld]=i##Tbl##_##Fld;
#
# SQLST_MAP_IND_I(RAGREEJ1,FORMFROMTMSTP);
#
# => gcc 3.3.4 gives the following error:
# source.c:173:40: pasting "[" and "RAGREEJ1" does not give a valid
# preprocessing token

You only need to paste together pieces that become a single identifier or
number or other single lexical entity. Assuming there is nothing missing
between the [ and ##, you don't need to paste the [ and Tbl parameter
together.

# The same code compiles fine on Win32 (MSVC 7.1) and on z/OS
#
# So what is wrong? The code or... the precompiler?

Possibly one compiler reanalyzes the characters of a #define expansion
and the other does not.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Where do you get those wonderful toys?
Nov 14 '05 #3

On Tue, 10 May 2005, Chris wrote:

We have a strange problem with macros:

#define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[ ##Tbl##_##Fld]=i##Tbl##_##Fld;

SQLST_MAP_IND_I(RAGREEJ1,FORMFROMTMSTP);

=> gcc 3.3.4 gives the following error:
source.c:173:40: pasting "[" and "RAGREEJ1" does not give a valid
preprocessing token
You've gotten two "correct but [almost] useless" answers so far, IMHO.
To summarize and elucidate: Your code is wrong. You are trying to paste
the strings '[' and 'RAGREEJ1', giving the token '[RAGREEJ1'. That's
not a valid token in C, so the compiler correctly diagnoses the error.
Your Microsoft and z/OS (whatever that is) compilers are broken,
or you're running them in non-conforming mode. Try turning up the
warning levels.

How to fix this problem: Simple. As has already been pointed out,
you don't want the token '[RAGREEJ1'. You want two tokens. So just
don't paste them together, and they'll stay two tokens!

Wrong: #define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[ ##Tbl##_##Fld]=i##Tbl##_##Fld;


Right:
#define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[Tbl##_##Fld]=i##Tbl##_##Fld;

Note the removal of the erroneous '##' between '[' and 'Tbl'.

HTH,
-Arthur
Nov 14 '05 #4
Alright, thanks alot!

"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> a écrit dans le message de
news: Pi**********************************...drew .cmu.edu...

On Tue, 10 May 2005, Chris wrote:

We have a strange problem with macros:

#define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[ ##Tbl##_##Fld]=i##Tbl##_##Fld;
SQLST_MAP_IND_I(RAGREEJ1,FORMFROMTMSTP);

=> gcc 3.3.4 gives the following error:
source.c:173:40: pasting "[" and "RAGREEJ1" does not give a valid
preprocessing token
You've gotten two "correct but [almost] useless" answers so far, IMHO.
To summarize and elucidate: Your code is wrong. You are trying to paste
the strings '[' and 'RAGREEJ1', giving the token '[RAGREEJ1'. That's
not a valid token in C, so the compiler correctly diagnoses the error.
Your Microsoft and z/OS (whatever that is) compilers are broken,
or you're running them in non-conforming mode. Try turning up the
warning levels.

How to fix this problem: Simple. As has already been pointed out,
you don't want the token '[RAGREEJ1'. You want two tokens. So just
don't paste them together, and they'll stay two tokens!

Wrong:
#define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[

##Tbl##_##Fld]=i##Tbl##_##Fld;
Right:
#define SQLST_MAP_IND_O(Tbl,Fld) i##Tbl##_O[Tbl##_##Fld]=i##Tbl##_##Fld;
Note the removal of the erroneous '##' between '[' and 'Tbl'.

HTH,
-Arthur

Nov 14 '05 #5
In article <Pi**********************************@unix43.andre w.cmu.edu>
Arthur J. O'Dwyer <aj*@nospam.andrew.cmu.edu> wrote:
You've gotten two "correct but [almost] useless" answers so far, IMHO.
To summarize and elucidate: Your code is wrong. You are trying to paste
the strings '[' and 'RAGREEJ1', giving the token '[RAGREEJ1'. That's
not a valid token in C, so the compiler correctly diagnoses the error.
Actually, I think one of the previous answers was useful. :-)

This is indeed the problem (that the ## token-pasting operator is
being used inappropriately). However:
Your Microsoft and z/OS (whatever that is) compilers are broken,
or you're running them in non-conforming mode. Try turning up the
warning levels.


These compilers are not actually *broken* (or at least, not provably
so from this example). If two pp-tokens pasted with "##" do not
form a valid new pp-token, the behavior is undefined, and no
diagnostic is required. The effect of that undefined behavior can
even be "the compiler does what you wanted after all".

Still, Arthur's fix is correct, and the new code is guaranteed to
work, rather than depending on compiler behavior.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #6

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

Similar topics

1
by: Cronus | last post by:
Hi the following code the g++ (g++ (GCC) 3.3.3 (Debian 20040422)) emits the error message that pasting of :: and hello is no valid preprocessor token. The g++ 2.95.3 accepts the code. I know...
6
by: Peter Ammon | last post by:
Let's say I need to swap two int values frequently. I would write a macro: #define swap(int a, int b) \ do { \ int temp = (a); \ (a) = (b); \ (b) = temp; \ } while (0)
3
by: Frodo Baggins | last post by:
Hi All, I have a piece of code (not written by me) that is failing on compile with the error: pasting "xdr_ndmp_connect_open_request" and "," does not give a valid preprocessing token The...
3
by: Gaurav Jain | last post by:
I am not sure what is wrong with this code ============================ #define cat(x,y) x##y main() { cat(cat(3,1),2); } ============================ Does it have to do anything with #...
13
by: Anthony de Almeida Lopes | last post by:
Hello, I am wondering why it is not possible to have a function-like macro like the following: #define __nothread(name) do { \ #ifdef _PTHREAD_H ...
15
by: Urs Thuermann | last post by:
I want to write a macro that produces debug output and has a variable number of arguments, so that I can use like this: int i; char *s; DBG("simple message\n"); DBG("message with an int...
3
by: kenkahn | last post by:
Given the following simple c program #include <stdio.h> enum ATTRTYPE { CFG_ATTR = 3000 }; int main() { #define xx(id) printf("ATTR=%s\n",#id);
1
by: borophyll | last post by:
Sorry for my perverse interest in the C preprocessor, but I have a question about a subtle matter. Yesterday, Eric brought up a point about the following case, indicating how preprocessing input...
6
by: Thant Tessman | last post by:
Back before C++ templates, I was taught a trick whereby one built C macros that built other C macros. I can't remember how the heck we did it. The problem is that there seems to be no standard way...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.