public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Preprocessor Problem?
@ 2000-05-27 13:52 linguist-gcc
  2000-05-27 14:27 ` Martin v. Loewis
  0 siblings, 1 reply; 7+ messages in thread
From: linguist-gcc @ 2000-05-27 13:52 UTC (permalink / raw)
  To: gcc

It seems odd that I did not find this issue in the FAQ, but I did not.  If
it is in there please sed -e 's/flame/where it is/' your reply.

I am attempting to port some c++ code that uses the following construct:

#define whatever(x) \
class _whatever_x { \
  void something() {} \
}

For some reason, it appears that gcc does not accept backslash escaped newlines in macro definitions?!?!?!  I haven't heard of anything in the new standard about this, have I missed something?

Joining all the lines, and removing the backslashes causes the (now even more horrible looking) code to compile, what what's up with that?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Preprocessor Problem?
  2000-05-27 13:52 Preprocessor Problem? linguist-gcc
@ 2000-05-27 14:27 ` Martin v. Loewis
  2000-05-27 16:06   ` Zack Weinberg
  0 siblings, 1 reply; 7+ messages in thread
From: Martin v. Loewis @ 2000-05-27 14:27 UTC (permalink / raw)
  To: linguist-gcc; +Cc: gcc

> I am attempting to port some c++ code that uses the following construct:
> 
> #define whatever(x) \
> class _whatever_x { \
>   void something() {} \
> }

> For some reason, it appears that gcc does not accept backslash
> escaped newlines in macro definitions?!?!?!

Sure it does. There is a chance that a Carriage Return character
follows the backslash, so there is whitespace after the backslash,
before the newline character. Of course, without seeing the original
source code, it is hard to tell.

Regards,
Martin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Preprocessor Problem?
  2000-05-27 14:27 ` Martin v. Loewis
@ 2000-05-27 16:06   ` Zack Weinberg
  2000-05-27 16:55     ` linguist-gcc
  0 siblings, 1 reply; 7+ messages in thread
From: Zack Weinberg @ 2000-05-27 16:06 UTC (permalink / raw)
  To: Martin v. Loewis; +Cc: linguist-gcc, gcc

On Sat, May 27, 2000 at 11:23:33PM +0200, Martin v. Loewis wrote:
> > I am attempting to port some c++ code that uses the following construct:
> > 
> > #define whatever(x) \
> > class _whatever_x { \
> >   void something() {} \
> > }
> 
> > For some reason, it appears that gcc does not accept backslash
> > escaped newlines in macro definitions?!?!?!
> 
> Sure it does. There is a chance that a Carriage Return character
> follows the backslash, so there is whitespace after the backslash,
> before the newline character.

... in which case a development snapshot will work as expected.

zw

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Preprocessor Problem?
  2000-05-27 16:06   ` Zack Weinberg
@ 2000-05-27 16:55     ` linguist-gcc
  2000-05-27 19:55       ` Zack Weinberg
  2000-05-27 21:49       ` Neil Booth
  0 siblings, 2 replies; 7+ messages in thread
From: linguist-gcc @ 2000-05-27 16:55 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: gcc

On Sat, 27 May 2000, Zack Weinberg wrote:

> On Sat, May 27, 2000 at 11:23:33PM +0200, Martin v. Loewis wrote:
> > > I am attempting to port some c++ code that uses the following construct:
> > > 
> > > #define whatever(x) \
> > > class _whatever_x { \
> > >   void something() {} \
> > > }
> > 
> > > For some reason, it appears that gcc does not accept backslash
> > > escaped newlines in macro definitions?!?!?!
> > 
> > Sure it does. There is a chance that a Carriage Return character
> > follows the backslash, so there is whitespace after the backslash,
> > before the newline character.
> 
> ... in which case a development snapshot will work as expected.
> 
> zw
> 

Thank you both ... these files were indeed dragged from a dos machine, with
their damn line endings intact.

I'm also pleased to know that the new version ignores this ... I've always
thought that the best way to handle CR's in a text file was to ignore them
intirely ... this would tend to be the 'right thing' in most cases ... like
shell scripts and programs, and eliminate one source of DOS annoyance.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Preprocessor Problem?
  2000-05-27 16:55     ` linguist-gcc
@ 2000-05-27 19:55       ` Zack Weinberg
  2000-05-27 21:49       ` Neil Booth
  1 sibling, 0 replies; 7+ messages in thread
From: Zack Weinberg @ 2000-05-27 19:55 UTC (permalink / raw)
  To: linguist-gcc; +Cc: gcc

On Sat, May 27, 2000 at 07:55:24PM -0400, linguist-gcc@rich-paul.net wrote:
> 
> 
> On Sat, 27 May 2000, Zack Weinberg wrote:
> 
> > On Sat, May 27, 2000 at 11:23:33PM +0200, Martin v. Loewis wrote:
> > > > I am attempting to port some c++ code that uses the following construct:
> > > > 
> > > > #define whatever(x) \
> > > > class _whatever_x { \
> > > >   void something() {} \
> > > > }
> > > 
> > > > For some reason, it appears that gcc does not accept backslash
> > > > escaped newlines in macro definitions?!?!?!
> > > 
> > > Sure it does. There is a chance that a Carriage Return character
> > > follows the backslash, so there is whitespace after the backslash,
> > > before the newline character.
> > 
> > ... in which case a development snapshot will work as expected.
> 
> Thank you both ... these files were indeed dragged from a dos machine, with
> their damn line endings intact.
> 
> I'm also pleased to know that the new version ignores this ... I've always
> thought that the best way to handle CR's in a text file was to ignore them
> intirely

It is slightly trickier than that.  \n, \r, \r\n, and \n\r are all
used as line terminators on platforms currently in use.  We have to
take care to handle them all equally.

zw

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Preprocessor Problem?
  2000-05-27 16:55     ` linguist-gcc
  2000-05-27 19:55       ` Zack Weinberg
@ 2000-05-27 21:49       ` Neil Booth
  2000-05-27 23:34         ` Per Bothner
  1 sibling, 1 reply; 7+ messages in thread
From: Neil Booth @ 2000-05-27 21:49 UTC (permalink / raw)
  To: linguist-gcc; +Cc: gcc

linguist-gcc@rich-paul.net wrote:-

> Thank you both ... these files were indeed dragged from a dos machine, with
> their damn line endings intact.
> 
> I'm also pleased to know that the new version ignores this ... I've always
> thought that the best way to handle CR's in a text file was to ignore them
> intirely ... this would tend to be the 'right thing' in most cases ... like
> shell scripts and programs, and eliminate one source of DOS annoyance.

Even better, soon (not quite in the snapshots yet) the preprocessor
will warn if it encounters a backslash separated by whitespace from
any of the 4 newline possibilities.

Neil.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Preprocessor Problem?
  2000-05-27 21:49       ` Neil Booth
@ 2000-05-27 23:34         ` Per Bothner
  0 siblings, 0 replies; 7+ messages in thread
From: Per Bothner @ 2000-05-27 23:34 UTC (permalink / raw)
  To: Neil Booth; +Cc: linguist-gcc, gcc

Neil Booth <NeilB@earthling.net> writes:

> Even better, soon (not quite in the snapshots yet) the preprocessor
> will warn if it encounters a backslash separated by whitespace from
> any of the 4 newline possibilities.

Or perhaps we should just silently ignore spaces between a backslash
and end-of-line.  That is non-traditional, but it is the only sensible
behavior, and I'm quite sure it is compatible with relevant C
standards.  In fact, it is the only clean behavior for "text files" as
opposed to "binary files".  A "text file" does not have semantic
meaning that depends on end-of-line conventions or other non-visible
characters.  Making the number of spaces at the end of a line be
signifigant means you can't represent your programs on punch cards, or
other fixed-line-length file formats, or (more importantly these days)
on printed output.  (I.e. you can't print out a C program and scan it
back in again.)

Inside a quoted string, we need to warn about any non-standard line
terminators (including cr-nl or backslash-space-nl), since the correct
behavior may be surprising and what ends up in the actual string may
not be what the programmer expects; elsewhere, there is no real need to
warn about backslash-space-nl, except to warn about something many
compilers get wrong.

(I'm satisfied that the compiler will now warn about backslash-space-nl
- but in such a case, it is more correct to ignore the space than to
ignore the backslash!)
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2000-05-27 23:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-27 13:52 Preprocessor Problem? linguist-gcc
2000-05-27 14:27 ` Martin v. Loewis
2000-05-27 16:06   ` Zack Weinberg
2000-05-27 16:55     ` linguist-gcc
2000-05-27 19:55       ` Zack Weinberg
2000-05-27 21:49       ` Neil Booth
2000-05-27 23:34         ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).