473,765 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

#defines and multiline expressions

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.

Feb 26 '06 #1
8 5048


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


Feb 26 '06 #2
David Lindauer wrote:

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 :)
the "ONLY_UNICO DE" 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.
Feb 26 '06 #3
TB
David Lindauer skrev:

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
Feb 26 '06 #4
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.
Feb 26 '06 #5
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 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: em******@asfand yarZIG.cjbZIG.n et
Feb 26 '06 #6
Asfand Yar Qazi wrote:
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: em******@asfand yarZIG.cjbZIG.n et
Feb 26 '06 #7
"Konrad" <ko************ **@wp.pl> wrote in message
news:dt******** **@nemesis.news .tpi.pl...
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

XXXXXXXXXXXXXXX XXXXXXXXXX
X joe.hotchkiss X
X at selex-sas.com X
XXXXXXXXXXXXXXX XXXXXXXXXX

Feb 27 '06 #8

(..)

OK, I got it now, thank you all!
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 :)
Feb 27 '06 #9

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

Similar topics

0
1957
by: Rasmus Fogh | last post by:
Dear All, I need a way of writing strings or arbitrary Python code that will a) allow the strings to be read again unchanged (like repr) b) write multiline strings as multiline strings instead of escaping the \n's. A repr function that output triple-quoted strings with explicit (non-escaped) linebreaks would be perfect.
32
3166
by: Elliot Temple | last post by:
Hi I have two questions. Could someone explain to me why Python is case sensitive? I find that annoying. Also, why aren't there multiline comments? Would adding them cause a problem of some sort? Thanks, Elliot
7
4051
by: Joel Finkel | last post by:
Folks, I have a form that has several TextBoxes, some of which have the TextMode set to MultiLine. Each is pre-loaded with data from a database. The user is allowed to modify each entry. The problem is that only the modified data from the SingleLine TextBoxes are returned. The original data are returned for the MultiLine TextBoxes. Also, if the page is sent to the server (for validation, for instance), only the modified data for the...
0
1098
by: GenoJoe | last post by:
I thought I understood this topic rather well until I ran the following procedure Private Sub Tes Dim oMatch As Matc Dim oMC As MatchCollection = Regex.Matches("abc" & vbCrLf & "abc", "abc$", RegexOptions.Multiline For Each oMatch In oM Console.WriteLine(oMatch.ToString Nex oMC = Regex.Matches("def" & vbCrLf & "def", "^def", RegexOptions.Multiline For Each oMatch In oM
40
4636
by: Edward Elliott | last post by:
At the risk of flogging a dead horse, I'm wondering why Python doesn't have any multiline comments. One can abuse triple-quotes for that purpose, but that's obviously not what it's for and doesn't nest properly. ML has a very elegant system for nested comments with (* and *). Using an editor to throw #s in front of every line has limitations. Your editor has to support it and you have to know how to use that feature. Not exactly...
9
3177
by: John Salerno | last post by:
How do you make a single string span multiple lines, but also allow yourself to indent the second (third, etc.) lines so that it lines up where you want it, without causing the newlines and tabs or spaces to be added to the string as well? Example (pretend this is all on one line): self.DTD = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"\n"http://www.w3.org/TR/html4/strict.dtd">\n\n'
7
2963
by: abcd | last post by:
When do I need to use a trailing slash to separate code over multiple lines. For example: x = "hello world, this is my multiline " + \ "string!!!!" x = {'name' : \ 'bob'}
5
2409
by: Grzegorz Danowski | last post by:
Hi, I'd like to read all lines of caption text from a string: .... Name ="Paragraph" Caption ="The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. " "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The qu" "ick brown fox jumps over the lazy dog. The quick
6
3800
by: Zdenek Maxa | last post by:
Hi all, I would like to perform regular expression replace (e.g. removing everything from within tags in a XML file) with multiple-line pattern. How can I do this? where = open("filename").read() multilinePattern = "^<tag.... <\/tag>$" re.search(multilinePattern, where, re.MULTILINE)
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.