Ansi standard with #defines and \ character

B

Brand Bogard

When creating a #define symbol like this,

#define SYMBOL1_OFFSET 100

#define SYMBOL2_OFFSET(SYMBOL1_OFFSET +\

50)

The 50) is on a new line. Can there be any whitespace after the \ character
according to the standard?
 
M

Mike Wahler

Brand Bogard said:
When creating a #define symbol like this,

#define SYMBOL1_OFFSET 100

#define SYMBOL2_OFFSET(SYMBOL1_OFFSET +\

50)

The 50) is on a new line. Can there be any whitespace after the \
character
according to the standard?

Yes, as long as the first whitespace character
after the \ is a newline (\n).

-Mike
 
T

Thad Smith

Mike said:
Yes, as long as the first whitespace character
after the \ is a newline (\n).

Correct. ;-)

Also, the definition of SYMBOL2_OFFSET is an error. I think the OP
intended to have a space before the left paren.
 
B

Brand Bogard

Mike Wahler said:
Yes, as long as the first whitespace character
after the \ is a newline (\n).

-Mike
And where is that little nugget piece of information documented? I'm not
questioning your answer, I just thought that standard was able to accomodate
more up to date parsers and lexers. Seems like a simple thing to allow.
 
K

Keith Thompson

Brand Bogard said:
And where is that little nugget piece of information documented? I'm not
questioning your answer, I just thought that standard was able to accomodate
more up to date parsers and lexers. Seems like a simple thing to allow.

It's documented in the standard.

Translation phase 2 is documented in C99 5.1.1.2p2:

Each instance of a backslash character (\) immediately followed by
a new-line character is deleted, splicing physical source lines to
form logical source lines. Only the last backslash on any
physical source line shall be eligible for being part of such a
splice. A source file that is not empty shall end in a new-line
character, which shall not be immediately preceded by a backslash
character before any such splicing takes place.

I agree that allowing arbitrary whitespace between a '\' and a
new-line character would be an improvement. As it is, a stray space
after a '\' can make a program illegal while being entirely invisible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top