one Macro more than one line

bridged with qdn.public.devtools
Post Reply
Yiwen

one Macro more than one line

Post by Yiwen » Tue Feb 25, 2003 7:04 pm

Hi,

The compiler reports error with any one Macro more than one line, for
example
#define RIGHT_CHECK(X,Y) ((((int)(X)->centre_right - (int)(Y)->centre_right)
<< 8) \

+ ((int)(X)->right - (int)(Y)->right))

while following code works:

#define RIGHT_CHECK(X,Y) ((((int)(X)->centre_right - (int)(Y)->centre_right)
<< 8) + ((int)(X)->right - (int)(Y)->right))

(1) I do not think gnu compiler does not support this.

(2) I do not like to put the macro in one line because there are too many
places and the code is hard to read.

Any solution?

Thanks a lot.

Yiwen

Oliver Koltermann

Re: one Macro more than one line

Post by Oliver Koltermann » Wed Feb 26, 2003 9:00 am

"Yiwen" <ywang@speechworks.com> writes:
The compiler reports error with any one Macro more than one line, for
example
#define RIGHT_CHECK(X,Y) ((((int)(X)->centre_right - (int)(Y)->centre_right)
8) \
+ ((int)(X)->right - (int)(Y)->right))
Hello Yiwen,

I've had similar experiences with another compiler in a source-tree
with mixed-up windows and unix lineendings. If the unix compiler
expects the unix lf, but there's an extra cr it can't interpret, the
trouble begins...

So check that all source files are stored in unix format. Hope this
helps.

Bye,
~OK~

Yiwen

Re: one Macro more than one line

Post by Yiwen » Wed Feb 26, 2003 3:30 pm

Oliver Koltermann,

Thanks a lot for your suggestion. You are right.

Hope QNX thinks it is a bug otherwise it is not convinent for customers.

Thanks again!

Yiwen

"Oliver Koltermann" <okoltermann@gmx.de> wrote in message
news:uwujn5sd0.fsf@gmx.de...
"Yiwen" <ywang@speechworks.com> writes:

The compiler reports error with any one Macro more than one line, for
example
#define RIGHT_CHECK(X,Y) ((((int)(X)->centre_right -
(int)(Y)->centre_right)
8) \
+ ((int)(X)->right - (int)(Y)->right))

Hello Yiwen,

I've had similar experiences with another compiler in a source-tree
with mixed-up windows and unix lineendings. If the unix compiler
expects the unix lf, but there's an extra cr it can't interpret, the
trouble begins...

So check that all source files are stored in unix format. Hope this
helps.

Bye,
~OK~

Randall Hyde

Re: one Macro more than one line

Post by Randall Hyde » Thu Feb 27, 2003 4:29 pm

"Yiwen" <ywang@speechworks.com> wrote in message
news:b3iln6$e1e$1@inn.qnx.com...
Oliver Koltermann,

Thanks a lot for your suggestion. You are right.

Hope QNX thinks it is a bug otherwise it is not convinent for customers.
Not a bug at all, just the way UNIX tools versus Windows tools
work. Be sure to run TEXTTO on all files you import from
a Windows system.

(hint: you'll get this same problem using GNU tools under
Linux and other variations on UNIX, as well).
Randy Hyde

Yiwen

Re: one Macro more than one line

Post by Yiwen » Thu Feb 27, 2003 4:48 pm

Randy Hyde,

I agree with you if I develop on a Unix/Linux machine. But ...

(1) I develop the software on Win2000.
(2) I edit files in QNX Momentics IDE editor. Source code edited by the IDE
itself (not the outside editor) gives the compiling error. It means
non-consistent between IDE and compiler.

So I think it is a bug.

Yiwen

"Randall Hyde" <randall.nospam.hyde@ustraffic.net> wrote in message
news:b3ldhn$hqb$1@inn.qnx.com...
"Yiwen" <ywang@speechworks.com> wrote in message
news:b3iln6$e1e$1@inn.qnx.com...
Oliver Koltermann,

Thanks a lot for your suggestion. You are right.

Hope QNX thinks it is a bug otherwise it is not convinent for customers.


Not a bug at all, just the way UNIX tools versus Windows tools
work. Be sure to run TEXTTO on all files you import from
a Windows system.

(hint: you'll get this same problem using GNU tools under
Linux and other variations on UNIX, as well).
Randy Hyde


Bill Caroselli

Re: one Macro more than one line

Post by Bill Caroselli » Thu Feb 27, 2003 5:23 pm

Yiwen <ywang@speechworks.com> wrote:
Randy Hyde,

I agree with you if I develop on a Unix/Linux machine. But ...

(1) I develop the software on Win2000.
(2) I edit files in QNX Momentics IDE editor. Source code edited by the IDE
itself (not the outside editor) gives the compiling error. It means
non-consistent between IDE and compiler.

So I think it is a bug.
The GNU compiler expects lines to end with '\n'. The macro preprocessor
requires the '\' character to be the at the end of the line to
escape (kinf of) the line feed character.

I.E. '\', '\n', not '\', '\r', '\n'.

Does your editor have an option to use UNIX style new-lines? Many do.

Randall Hyde

Re: one Macro more than one line

Post by Randall Hyde » Fri Feb 28, 2003 4:24 pm

"Yiwen" <ywang@speechworks.com> wrote in message
news:b3leln$j0h$1@inn.qnx.com...
Randy Hyde,

I agree with you if I develop on a Unix/Linux machine. But ...

(1) I develop the software on Win2000.
(2) I edit files in QNX Momentics IDE editor. Source code edited by the
IDE
itself (not the outside editor) gives the compiling error. It means
non-consistent between IDE and compiler.

So I think it is a bug.

Yiwen
No, it is *not* a bug :-)
If I were developing on an EBCDIC machine, I couldn't rightly
expect my text files to work properly under an ASCII system.
This is the same effect.

I, too, develop under Windows.
I use a text editor (CodeWright) that's smart enough to deal
with different line endings and adjust properly. I'd suggest
you get such an editor (e.g., UltraEdit32, CodeWright,
dozens of others). At some point or another, you're going
to have a file that contains carriage returns in it; fortunately,
most of these editors contain functions to do the conversion
from one format to another (or you can use TEXTTO under
QNX). That's just part of life.

If it makes you feel any better, UNIX was using linefeeds
for EOLN well before CP/M-80 came along and used
the two-character sequence <CR><LF>. DOS and
Windows, of course, got that sequence from CP/M-80
(whether CP/M-80 inherited it from RSTS or RT-11
is a good question, I don't remember).

The bottom line is that *Windows* has a similar "bug".
Try loading a UNIX text file into notepad.exe and
watch what happens.

To make matters worse, the Macintosh uses single
carriage returns as EOLN markers. So there's yet
a third type of text data file you've got to deal with.
(AFAIK, TEXTTO under QNX doesn't handle Mac
files, but I've got my own version of TEXTTO running
under Windows that deals with all three text file formats).
Randy Hyde

Gerhard Wesp

Re: one Macro more than one line

Post by Gerhard Wesp » Mon Mar 03, 2003 12:13 pm

Randall Hyde <randall.nospam.hyde@ustraffic.net> wrote:
(hint: you'll get this same problem using GNU tools under
Linux and other variations on UNIX, as well).
Not true. I just tried the following example:

#define foo\^M
bar^M

gcc 3.2.2 under Linux compiles this without complaints. (It should fail
with a syntax error if the continuation character isn't recognized.)

-Gerhard
--
| voice: +43 (0)676 6253725 *** web: http://www.cosy.sbg.ac.at/~gwesp/
|
| Passts auf, seid's vuasichdig, und lossds eich nix gfoin!
| -- Dr. Kurt Ostbahn

Bill Caroselli

Re: one Macro more than one line

Post by Bill Caroselli » Mon Mar 03, 2003 7:47 pm

Randall Hyde <randall.nospam.hyde@ustraffic.net> wrote:
If it makes you feel any better, UNIX was using linefeeds
for EOLN well before CP/M-80 came along and used
the two-character sequence <CR><LF>. DOS and
Windows, of course, got that sequence from CP/M-80
(whether CP/M-80 inherited it from RSTS or RT-11
is a good question, I don't remember).
I'm pretty sure that this pre-dates any modern OS. It is simply what
is required for older mechanical printers. One character forced the
print head (carrage) to the left hand column and one scrolled the paper
up one line.

Incidenly, it was <CR><LF> and not <LF><CR> because the carrage return
could be a lengthy operation. So the printer could line feed *while*
it was still returning the carrage. Many old timers will remember when
software would have to pad tralling <NULL>s to the <CR><LF> because
of the length of time it took to return the carrage.

The bottom line is that *Windows* has a similar "bug".
Try loading a UNIX text file into notepad.exe and
watch what happens.

To make matters worse, the Macintosh uses single
carriage returns as EOLN markers. So there's yet
a third type of text data file you've got to deal with.
(AFAIK, TEXTTO under QNX doesn't handle Mac
files, but I've got my own version of TEXTTO running
under Windows that deals with all three text file formats).
Randy Hyde
And hey, QNX 2 used the <US> (Unit Seperator) character for EOL.

--
Bill Caroselli -- Q-TPS Consulting
1-(626) 824-7983
qtps@earthlink.net

Randall Hyde

Re: one Macro more than one line

Post by Randall Hyde » Mon Mar 03, 2003 7:52 pm

"Gerhard Wesp" <gwesp@cosy.sbg.ac.at> wrote in message
news:b3vgsv$p7d$1@inn.qnx.com...
Randall Hyde <randall.nospam.hyde@ustraffic.net> wrote:
(hint: you'll get this same problem using GNU tools under
Linux and other variations on UNIX, as well).

Not true. I just tried the following example:

#define foo\^M
bar^M
Then this is something they've corrected recently...

Post Reply

Return to “qdn.public.devtools”