C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

#defines and multiline expressions

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Konrad
Guest





PostPosted: Sun Feb 26, 2006 6:06 pm    Post subject: #defines and multiline expressions Reply with quote



Hello,
Stupid question, but I just don't remember, here is what I want to do:

#ifdef _UNICODE
#define ONLY_UNICODE(t) t
#else
#define ONLY_UNICODE(t)
#endif

You know what it does, but I'm not sure, if I actually can use #defines
with multiline code? I'm just not sure, here is an example of using this:

ONLY_UNICODE
(
MessageBox(_T("A lot of lines"));
MessageBox(_T("are included"));
MessageBox(_T("as a paremeter of this directive"));
);

It does compile, but maybe I should be worry about it ? I do remember
that there was something about including more than one line as a
#define's parameter, I somehow don't remember what was that.
Back to top
David Lindauer
Guest





PostPosted: Sun Feb 26, 2006 7:06 pm    Post subject: Re: #defines and multiline expressions Reply with quote



Konrad wrote:

Quote:
Hello,
Stupid question, but I just don't remember, here is what I want to do:

#ifdef _UNICODE
#define ONLY_UNICODE(t) t
#else
#define ONLY_UNICODE(t)
#endif

You know what it does, but I'm not sure, if I actually can use #defines
with multiline code? I'm just not sure, here is an example of using this:

ONLY_UNICODE
(
MessageBox(_T("A lot of lines"));
MessageBox(_T("are included"));
MessageBox(_T("as a paremeter of this directive"));
);

It does compile, but maybe I should be worry about it ? I do remember
that there was something about including more than one line as a
#define's parameter, I somehow don't remember what was that.

#define ONLY_UNICODE( \
MessageBox(_T("A lot of lines")); \
MessageBox(_T("are included")); \
MessageBox(_T("as a paremeter of this directive")); \
);

might work... the '\' means concatenate two lines together...
Back to top
Konrad
Guest





PostPosted: Sun Feb 26, 2006 8:06 pm    Post subject: Re: #defines and multiline expressions Reply with quote



David Lindauer wrote:
Quote:

Konrad wrote:


Hello,
Stupid question, but I just don't remember, here is what I want to do:

#ifdef _UNICODE
#define ONLY_UNICODE(t) t
#else
#define ONLY_UNICODE(t)
#endif

You know what it does, but I'm not sure, if I actually can use #defines
with multiline code? I'm just not sure, here is an example of using this:

ONLY_UNICODE
(
MessageBox(_T("A lot of lines"));
MessageBox(_T("are included"));
MessageBox(_T("as a paremeter of this directive"));
);

It does compile, but maybe I should be worry about it ? I do remember
that there was something about including more than one line as a
#define's parameter, I somehow don't remember what was that.


#define ONLY_UNICODE( \
MessageBox(_T("A lot of lines")); \
MessageBox(_T("are included")); \
MessageBox(_T("as a paremeter of this directive")); \
);

might work... the '\' means concatenate two lines together...





Thanks, but it's not what I meant, I was not clear enough I Smile
the "ONLY_UNICODE" is defined OK, it is how it is supposed to be, the
question is: Can I _use_ it as in my example, that is - can I pass
multiline parameter to it, I know it compiles, I just wanted to know if
there are things to be worry about.
Back to top
TB
Guest





PostPosted: Sun Feb 26, 2006 8:06 pm    Post subject: Re: #defines and multiline expressions Reply with quote

David Lindauer skrev:
Quote:

Konrad wrote:

Hello,
Stupid question, but I just don't remember, here is what I want to do:

#ifdef _UNICODE
#define ONLY_UNICODE(t) t
#else
#define ONLY_UNICODE(t)
#endif

You know what it does, but I'm not sure, if I actually can use #defines
with multiline code? I'm just not sure, here is an example of using this:

ONLY_UNICODE
(
MessageBox(_T("A lot of lines"));
MessageBox(_T("are included"));
MessageBox(_T("as a paremeter of this directive"));
);

It does compile, but maybe I should be worry about it ? I do remember
that there was something about including more than one line as a
#define's parameter, I somehow don't remember what was that.

#define ONLY_UNICODE( \
MessageBox(_T("A lot of lines")); \
MessageBox(_T("are included")); \
MessageBox(_T("as a paremeter of this directive")); \
);

might work... the '\' means concatenate two lines together...


I don't think that was what he was asking. He wondered if the macro
argument could span multiple lines. And the answer is yes, with the
exception that possible commas will interfere.

#define MACRO(C) C

int main() {
MACRO
(
int x;
x = 3;
)
return 0;
}

But this doesn't compile:

#define MACRO(C) C

int main() {
MACRO
(
int x,y;
x = 3;
)
return 0;
}

--
TB @ SWEDEN
Back to top
Marc Thrun
Guest





PostPosted: Sun Feb 26, 2006 9:06 pm    Post subject: Re: #defines and multiline expressions Reply with quote

TB wrote:
Quote:
David Lindauer skrev:


snip


#define ONLY_UNICODE( \
MessageBox(_T("A lot of lines")); \
MessageBox(_T("are included")); \
MessageBox(_T("as a paremeter of this directive")); \
);

might work... the '\' means concatenate two lines together...


I don't think that was what he was asking. He wondered if the macro
argument could span multiple lines. And the answer is yes, with the
exception that possible commas will interfere.

#define MACRO(C) C

int main() {
MACRO
(
int x;
x = 3;
)
return 0;
}

But this doesn't compile:

#define MACRO(C) C

int main() {
MACRO
(
int x,y;
x = 3;
)
return 0;
}


I would try something like

#ifdef _UNICODE
#define ONLY_UNICODE
#else
#define ONLY_UNICODE while(0)
#endif

int main()
{
ONLY_UNICODE
{
/* code */
}
return 0;
}

This has no problems with commas and a compiler will most likely
optimize the while(0) loop away anyway.
Back to top
Asfand Yar Qazi
Guest





PostPosted: Sun Feb 26, 2006 11:06 pm    Post subject: Re: #defines and multiline expressions Reply with quote

Marc Thrun wrote:
Quote:
TB wrote:

David Lindauer skrev:


snip



#define ONLY_UNICODE( \
MessageBox(_T("A lot of lines")); \
MessageBox(_T("are included")); \
MessageBox(_T("as a paremeter of this directive")); \
);

might work... the '\' means concatenate two lines together...


I don't think that was what he was asking. He wondered if the macro
argument could span multiple lines. And the answer is yes, with the
exception that possible commas will interfere.

#define MACRO(C) C

int main() {
MACRO
(
int x;
x = 3;
)
return 0;
}

But this doesn't compile:

#define MACRO(C) C

int main() {
MACRO
(
int x,y;
x = 3;
)
return 0;
}


I would try something like

#ifdef _UNICODE
#define ONLY_UNICODE
#else
#define ONLY_UNICODE while(0)
#endif

int main()
{
ONLY_UNICODE
{
/* code */
}
return 0;
}

This has no problems with commas and a compiler will most likely
optimize the while(0) loop away anyway.

You can have multi-line arguments to argument-taking macros?!?! Bloody hell,
I never knew that!

This could revolutionise something I was stuck on in one of my projects...

--
To reply, take of all ZIGs !!

Alternative email address: emailZIG (AT) asfandyarZIG (DOT) cjbZIG.net
Back to top
Asfand Yar Qazi
Guest





PostPosted: Sun Feb 26, 2006 11:06 pm    Post subject: Re: #defines and multiline expressions Reply with quote

Asfand Yar Qazi wrote:
Quote:
Marc Thrun wrote:

TB wrote:

David Lindauer skrev:


snip



#define ONLY_UNICODE( \
MessageBox(_T("A lot of lines")); \
MessageBox(_T("are included")); \
MessageBox(_T("as a paremeter of this directive")); \
);

might work... the '\' means concatenate two lines together...


I don't think that was what he was asking. He wondered if the macro
argument could span multiple lines. And the answer is yes, with the
exception that possible commas will interfere.

#define MACRO(C) C

int main() {
MACRO
(
int x;
x = 3;
)
return 0;
}

But this doesn't compile:

#define MACRO(C) C

int main() {
MACRO
(
int x,y;
x = 3;
)
return 0;
}



I must say that I've bettered myself. Try the following code:

#define MACRO(...) __VA_ARGS__

int main() {
MACRO
(
int x,y;
x = 3;
)
}

Note: only works in C99 mode. Worked alright for me on GCC (using g++
front-end as well), don't know about other compilers. But, we're getting
there :-)

--
To reply, take of all ZIGs !!

Alternative email address: emailZIG (AT) asfandyarZIG (DOT) cjbZIG.net
Back to top
Joe Hotchkiss
Guest





PostPosted: Mon Feb 27, 2006 9:06 am    Post subject: Re: #defines and multiline expressions Reply with quote

"Konrad" <konradp_removit_ (AT) wp (DOT) pl> wrote in message
news:dtspjf$g69$1 (AT) nemesis (DOT) news.tpi.pl...
Quote:
Hello,
Stupid question, but I just don't remember, here is what I want to do:

#ifdef _UNICODE
#define ONLY_UNICODE(t) t
#else
#define ONLY_UNICODE(t)
#endif

You know what it does, but I'm not sure, if I actually can use
#defines
with multiline code? I'm just not sure, here is an example of using
this:

ONLY_UNICODE
(
MessageBox(_T("A lot of lines"));
MessageBox(_T("are included"));
MessageBox(_T("as a paremeter of this directive"));
);

What's wrong with
#ifdef _UNICODE
MessageBox(_T("A lot of lines"));
MessageBox(_T("are included"));
MessageBox(_T("as a paremeter of this directive"));
#endif

--
Regards,

Joe Hotchkiss,
http://joe.hotchkiss.com
http://harrowsubaqua.org.uk

XXXXXXXXXXXXXXXXXXXXXXXXX
X joe.hotchkiss X
X at selex-sas.com X
XXXXXXXXXXXXXXXXXXXXXXXXX
Back to top
Konrad
Guest





PostPosted: Mon Feb 27, 2006 7:06 pm    Post subject: Re: #defines and multiline expressions Reply with quote

(..)

OK, I got it now, thank you all!

Quote:
What's wrong with
#ifdef _UNICODE
MessageBox(_T("A lot of lines"));
MessageBox(_T("are included"));
MessageBox(_T("as a paremeter of this directive"));
#endif

Mine is shorter Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.