473,326 Members | 2,114 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,326 software developers and data experts.

Compile error about MACRO

Hello everyone,
The compile error of the following code is,

foo.cpp(7) : error C2146: syntax error : missing ';' before identifier
'_'
foo.cpp(7) : error C2065: '_' : undeclared identifier
foo.cpp(7) : error C2143: syntax error : missing ';' before 'string'

I do not know why there is errors. I think in MERGE macro, the value
of parameter a is hello and the value of parameter b is world in my
case, and I defined hello_world to "H E L L O", it should be fine...

Any ideas?

Expand|Select|Wrap|Line Numbers
  1. #define MERGE(a,b)  a ## _ ## b
  2. #define hello_world "H E L L O"
  3.  
  4. int foo()
  5. {
  6. char* p0;
  7. p0 = MERGE("hello", "world");
  8.  
  9. return 0;
  10. }
  11.  

thanks in advance,
George
Nov 26 '07 #1
2 2522
George2 wrote:
Hello everyone,
The compile error of the following code is,

foo.cpp(7) : error C2146: syntax error : missing ';' before identifier
'_'
foo.cpp(7) : error C2065: '_' : undeclared identifier
foo.cpp(7) : error C2143: syntax error : missing ';' before 'string'

I do not know why there is errors. I think in MERGE macro, the value
of parameter a is hello and the value of parameter b is world in my
case, and I defined hello_world to "H E L L O", it should be fine...
No, a is "hello" and b is "world" so your macro produces "hello"_"world".

--
Ian Collins.
Nov 26 '07 #2
On Nov 26, 2:10 pm, George2 <george4acade...@yahoo.comwrote:
Hello everyone,

The compile error of the following code is,

foo.cpp(7) : error C2146: syntax error : missing ';' before identifier
'_'
foo.cpp(7) : error C2065: '_' : undeclared identifier
foo.cpp(7) : error C2143: syntax error : missing ';' before 'string'

I do not know why there is errors. I think in MERGE macro, the value
of parameter a is hello and the value of parameter b is world in my
case, and I defined hello_world to "H E L L O", it should be fine...

Any ideas?

Expand|Select|Wrap|Line Numbers
  1. #define MERGE(a,b)  a ## _ ## b
  2. #define hello_world "H E L L O"
  3. int foo()
  4. {
  5.         char* p0;
  6.         p0 = MERGE("hello", "world");
Expand|Select|Wrap|Line Numbers
  1. ~~~~~~~~~~~~~~~~~~~~~~~~MERGE(hello,world);
  2.         
  3.                 >
  4.         return 0;}
  5.  
  6.  
>
thanks in advance,
George
Nov 26 '07 #3

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

Similar topics

7
by: mrstephengross | last post by:
Hi folks! I'm trying to do something that I'm pretty sure you can't do in C++. But what the heck! Maybe it can work... I want to figure out how to use macros and templates to turn the following...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
8
by: Chris Bailiss | last post by:
Hi all, I am unable to run any VBA in access XP. I get the compile error of 'Error In Loading DLL'. Behaviour of the wizards is also patchy. I cannot get past the first screen in most (i.e....
6
by: FTSoJ | last post by:
On a file A.c I define the structure T1 typedef struct { int dummy; int age; char lastname ; char firstname; } T1_user; On a file B.c I define a strcuture T2
3
by: Saxman | last post by:
I need to copy/paste in Excel, but with a delay built in between each copy/paste operation. Below is the code which gives me a compile error on the 2nd Sub Delay(). It is a simple copy from...
14
by: Urs Thuermann | last post by:
What is the most elegant way to check certain conditions at compile time? I.e. I want a compile time error to be generated if for example the size of a struct is not a multiple of 4 or if one...
4
by: Chris | last post by:
Hello all, Using g++ 3.3.1 on Linux ("Linux From Scratch") I have a data structure SCSIParams_t that I wish to print out, field-by-field. Rather than code a long line of the form std::cout <<...
11
by: Francois Grieu | last post by:
Hi, I'm using an assert()-like macro to test a constant expression at compile time #define ASSERT(condition) struct{char assert_failure;} The idea is that this macro cause a compilation...
2
by: rocky102 | last post by:
I am a novice old timer who enjoys fooling around with excel, I copied this macro from and old computer and wanted to use it one a new one I got. Its supposed to draw a line across a row when...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.