Re: Compile error about MACRO

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



George schrieb:

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...

Wrong. In the MERGE macro, a is replaced by the string "hello", not the token hello. You only use quotes in macro arguments when you want strings.


Any ideas?

[Code]
#define MERGE(a,b) a ## _ ## b
#define hello_world "H E L L O"

int foo()
{
char* p0;
p0 = MERGE("hello", "world");

This expands to:
p0 = "Hello"_"world";

which is definately a syntax error. Try:
p0 = MERGE(hello, world);

You are just experiencing the difference between a string and a token. The ## operator works on tokens not on strings. To merge strings you do not need the ## operator.

Norbert

.



Relevant Pages

  • Re: Using Japanese and English strings, encodings
    ... using edict + CLISP + araneida. ... It would be much better if you had a single LANG macro, ... It keeps screwing up the EUC-JP encoding of any parameters I ... Internally, strings are 16 bit characters, I think. ...
    (comp.lang.lisp)
  • Re: override locale computer settings
    ... So you could make that macro run each time you open the workbook--just name it ... If you put those strings on a separate worksheet, ... I do not want to have the the format of the region of the user, ...
    (microsoft.public.excel.misc)
  • Re: Put Variables giving problems
    ... > though I could run the macro on the same data, ... > 'couple extra strings, singles, and dates ... > dim MA as myDataType ... > Put myF, recpos, MA ...
    (microsoft.public.vb.syntax)
  • Re: Concatenation of a Formula
    ... If you can't use a macro to do this then it's gonna be a real kludge! ... Set myRng = Nothing ... strings to them; this would create new, ... (I would get rid of the "=" sign in the original formula by ...
    (microsoft.public.excel)
  • Home Stretch! *
    ... Well here is the Macro right now... ... Uses regular expressions For search To make sure found strings are ... Dim RgExp As Object ... If rg Is Nothing Then Exit Sub ...
    (microsoft.public.excel.programming)