By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,341 Members | 1,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,341 IT Pros & Developers. It's quick & easy.

Ansi standard with #defines and \ character

P: n/a
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?
May 10 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Brand Bogard" <br**********@motorola.com> wrote in message
news:e3**********@newshost.mot.com...
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
May 10 '06 #2

P: n/a
Mike Wahler wrote:
"Brand Bogard" <br**********@motorola.com> wrote in message
news:e3**********@newshost.mot.com...
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).


Correct. ;-)

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

--
Thad
May 10 '06 #3

P: n/a
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:DZ**************@newsread2.news.pas.earthlink .net...

"Brand Bogard" <br**********@motorola.com> wrote in message
news:e3**********@newshost.mot.com...
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

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.
May 10 '06 #4

P: n/a
"Brand Bogard" <br**********@motorola.com> writes:
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:DZ**************@newsread2.news.pas.earthlink .net...
"Brand Bogard" <br**********@motorola.com> wrote in message
news:e3**********@newshost.mot.com...
> 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).

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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.