Re: #warning must be protected by #if __GNUC__ in headers?

2003-03-10 Thread Terry Lambert
Garrett Wollman wrote:
> `#if __GNUC__' wouldn't help matters; every preprocessor has to read
> and interpret every preprocessor directive (so that `#else' and
> `#endif' can be recognized).

I thought that the other discussion had concluded that:

#if 0
...
#else

Or:

#if 0
...
#endif

Should ignore everything *except* "#else" or "#elif" or "#endif"?

I remember when GCC used to start "nethack" any time you used a
"#pragma" in an unprotected block, but not otherwise... ;^).

-- Terry

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


Re: #warning must be protected by #if __GNUC__ in headers?

2003-03-10 Thread Terry Lambert
Craig Rodrigues wrote:
> In , I see:
> 
> #if __GNUC__
> #warning "No user-serviceable parts inside."
> #endif
> 
> Does the use of #warning need to be protected by
> #if __GNUC__ in FreeBSD header files?

Yes.  It is a preprocessor directive specific the GCC preprocessor.
This was discussed in great detail about a month ago, when the
people trying to get TenDRA to compile FreeBSD discovered to their
horror that TenDRA's preprocessor incorrectly assigns meaning to
code that's #if'ed out, and blew chunks on the #warning, when it
should have ignored it.

> Some other header files check for __GNUC__ before using #warning,
> such as , but  does not.

 is wrong.  Please see the original discussion for
more details.

-- Terry

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


Re: #warning must be protected by #if __GNUC__ in headers?

2003-03-08 Thread Maxime Henrion
Garance A Drosihn wrote:
> At 2:33 PM -0500 3/8/03, Garance A Drosihn wrote:
> >
> >By adding that #warning, you are going to have a compile-time error
> >on some compilers, whether or not you want it.  Hiding it inside of
> >an #if/#endif will help for some compilers, but not on all of them.
> 
> Er, I should note that I do like the idea of using #warnings for
> some things.  All I meant to say was that I would not waste my time
> putting it inside of a #if __GNUC__.  GNUC is not the only compiler
> which understands it, and for some of the compilers which do not
> understand it, you're still going to get a compile-time error even
> if it's inside that #if/#endif.

That's a problem, #warning is not supposed to give a compile-time error
but a compile-time warning.  The point is moot for the kernel where we
use -Werror, but it's very valid for userland.

> By putting it inside #if __GNUC__,
> you're just confusing things by making it look like the warning
> itself is *because of* GCC.

Maxime

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


Re: #warning must be protected by #if __GNUC__ in headers?

2003-03-08 Thread Garance A Drosihn
At 2:33 PM -0500 3/8/03, Garance A Drosihn wrote:
By adding that #warning, you are going to have a compile-time error
on some compilers, whether or not you want it.  Hiding it inside of
an #if/#endif will help for some compilers, but not on all of them.
Er, I should note that I do like the idea of using #warnings for
some things.  All I meant to say was that I would not waste my time
putting it inside of a #if __GNUC__.  GNUC is not the only compiler
which understands it, and for some of the compilers which do not
understand it, you're still going to get a compile-time error even
if it's inside that #if/#endif.  By putting it inside #if __GNUC__,
you're just confusing things by making it look like the warning
itself is *because of* GCC.
--
Garance Alistair Drosehn=   [EMAIL PROTECTED]
Senior Systems Programmer   or  [EMAIL PROTECTED]
Rensselaer Polytechnic Instituteor  [EMAIL PROTECTED]
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


Re: #warning must be protected by #if __GNUC__ in headers?

2003-03-08 Thread Garance A Drosihn
At 10:48 AM -0800 3/8/03, Marcel Moolenaar wrote:
On Sat, Mar 08, 2003 at 12:28:13PM -0500, Garrett Wollman wrote:

 > `#if __GNUC__' wouldn't help matters; every preprocessor has to
 > read and interpret every preprocessor directive (so that `#else'
 > and `#endif' can be recognized).
I don't think preprocessors should interpret directives when they
are dead (ie part of an #if block or #else block that is not to
be compiled).
I tried to use this once, on a cross-platform program I wrote.  I
can tell you that some compilers will choke on a #warning, even if
it is inside a #if/#endif.  And other compilers will choke on #warn,
even if *it* is in a #if/#endif.  (note: some compilers which do not
recognize #warning will support #warn for the same thing).
By adding that #warning, you are going to have a compile-time error
on some compilers, whether or not you want it.  Hiding it inside of
an #if/#endif will help for some compilers, but not on all of them.
--
Garance Alistair Drosehn=   [EMAIL PROTECTED]
Senior Systems Programmer   or  [EMAIL PROTECTED]
Rensselaer Polytechnic Instituteor  [EMAIL PROTECTED]
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


Re: #warning must be protected by #if __GNUC__ in headers?

2003-03-08 Thread Marcel Moolenaar
On Sat, Mar 08, 2003 at 12:28:13PM -0500, Garrett Wollman wrote:
> 
> `#if __GNUC__' wouldn't help matters; every preprocessor has to read
> and interpret every preprocessor directive (so that `#else' and
> `#endif' can be recognized).

I don't think preprocessors should interpret directives when they are
dead (ie part of an #if block or #else block that is not to be compiled).
They should merely scan the block for #else, #endif and the likes to keep
track of nesting, but should otherwise ignore anything it sees. For how
does it matter if a directive is valid or invalid when you're not acting
upon it anyway? One can even claim that emitting an error or warning *is*
reaction upon the directive.

-- 
 Marcel Moolenaar USPA: A-39004  [EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


Re: #warning must be protected by #if __GNUC__ in headers?

2003-03-08 Thread Marcel Moolenaar
On Sat, Mar 08, 2003 at 11:19:43AM -0500, Craig Rodrigues wrote:
> Hi,
> 
> In , I see:
> 
> #if __GNUC__
> #warning "No user-serviceable parts inside."
> #endif
> 
> 
> Does the use of #warning need to be protected by
> #if __GNUC__ in FreeBSD header files?  I am working
> on something similar for .

I think the use of #warning should be protected against abuse :-)

In general I probably would opt to not protect it with #if __GNUC__
because #warning is not specific to gcc and since we're only compiling
with gcc (officially) it's better to have it fail when somebody does
use a different compiler. I think the discussion that it will trigger
will yield a less gratuitous convention. Possibly documented. YMMV.

-- 
 Marcel Moolenaar USPA: A-39004  [EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


Re: #warning must be protected by #if __GNUC__ in headers?

2003-03-08 Thread Dan Nelson
In the last episode (Mar 08), Garrett Wollman said:
> On Sat, 8 Mar 2003 11:19:43 -0500, Craig Rodrigues <[EMAIL PROTECTED]> said:
> > Does the use of #warning need to be protected by
> > #if __GNUC__ in FreeBSD header files?
> 
> No, it needs to be replaced by the standard `#error' directive
> instead.  I asked portmgr to do a run on the portsd cluster with this
> change to look for ports that mistakenly include this file, but I
> never heard back and portmgr is now busy doing the packages for 4.8.
> 
> `#if __GNUC__' wouldn't help matters; every preprocessor has to read
> and interpret every preprocessor directive (so that `#else' and
> `#endif' can be recognized).

This was discussed on the tendra list, and it was determined that the
preprocessor should not complain about unknown directives at all and
should pass them unchanged to the compiler.

http://lists.tendra.org/tendra-dev/20021215/msg5.html

If the #warning directive is wrapped with an appropriate #if SOMETHING
conditional to hide it from compilers that do not understand it, it
should be okay.


-- 
Dan Nelson
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


#warning must be protected by #if __GNUC__ in headers?

2003-03-08 Thread Garrett Wollman
< said:

> Does the use of #warning need to be protected by
> #if __GNUC__ in FreeBSD header files?

No, it needs to be replaced by the standard `#error' directive
instead.  I asked portmgr to do a run on the portsd cluster with this
change to look for ports that mistakenly include this file, but I
never heard back and portmgr is now busy doing the packages for 4.8.

`#if __GNUC__' wouldn't help matters; every preprocessor has to read
and interpret every preprocessor directive (so that `#else' and
`#endif' can be recognized).

-GAWollman


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message


#warning must be protected by #if __GNUC__ in headers?

2003-03-08 Thread Craig Rodrigues
Hi,

In , I see:

#if __GNUC__
#warning "No user-serviceable parts inside."
#endif


Does the use of #warning need to be protected by
#if __GNUC__ in FreeBSD header files?  I am working
on something similar for .

Some other header files check for __GNUC__ before using #warning,
such as , but  does not.

Thanks.
-- 
Craig Rodrigues
http://home.attbi.com/~rodrigc
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message