PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > Compile error about MACRO
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Compile error about MACRO

Réponse
 
LinkBack Outils de la discussion
Vieux 26/11/2007, 06h10   #1
George2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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?

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

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

return 0;
}

thanks in advance,
George
  Réponse avec citation
Vieux 26/11/2007, 06h18   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compile error about MACRO

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.
  Réponse avec citation
Vieux 26/11/2007, 12h55   #3
echo.sj
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Compile error about MACRO

On Nov 26, 2:10 pm, George2 <george4acade...@yahoo.com> 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...
>
> 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");
Code:
~~~~~~~~~~~~~~~~~~~~~~~~MERGE(hello,world);
>
>         return 0;}
>
> 

>
> thanks in advance,
> George


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h23.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10831 seconds with 11 queries