* [9fans] PCC - #if
@ 2007-05-04 20:23 lucio
2007-05-04 21:17 ` Russ Cox
0 siblings, 1 reply; 6+ messages in thread
From: lucio @ 2007-05-04 20:23 UTC (permalink / raw)
To: 9fans
I have the following diff:
term% diff ../../../openldap-2.3.32/include/ac/time.h ../../include/ac
20c20
< #if defined(TIME_WITH_SYS_TIME)
---
> #if TIME_WITH_SYS_TIME
23c23
< #elif defined(HAVE_SYS_TIME_H)
---
> #elif HAVE_SYS_TIME_H
and I'm curious whether it's a slip in the OpenLDAP source or in PCC
that the one works and the other doesn't. I do not have an ANSI
standard to check against, but my gut feel is that OpenLDAP is
stretching a limit. If not, then PCC ought to be corrected, it
reports (the "elsif" is certainly mistaken):
cpp: ../../include/ac/time.h:20 csn.c:47 Syntax error in #if/#elsif
++L
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] PCC - #if
2007-05-04 20:23 [9fans] PCC - #if lucio
@ 2007-05-04 21:17 ` Russ Cox
2007-05-04 21:35 ` lucio
0 siblings, 1 reply; 6+ messages in thread
From: Russ Cox @ 2007-05-04 21:17 UTC (permalink / raw)
To: 9fans
term% diff ../../../openldap-2.3.32/include/ac/time.h ../../include/ac
20c20
< #if defined(TIME_WITH_SYS_TIME)
---
> #if TIME_WITH_SYS_TIME
23c23
< #elif defined(HAVE_SYS_TIME_H)
---
> #elif HAVE_SYS_TIME_H
The < version is always valid; the > version is often valid.
After
#define A 1
#define B 0
#define C /* nothing! */
#undef D
These are like #if 1:
#if defined(A)
#if defined(B)
#if defined(C)
#if A
These are like #if 0:
#if defined(D)
#if B
#if D
and this is invalid:
#if C
(The rule for variables appearing in #if is that macros
expand and names that make it through macro expansion
turn into zeros, so `#if D' is like `#if 0' but `#if C' is like `#if',
which is missing an expression.)
So if the config.h for this program has done, say,
#define TIME_WITH_SYS_TIME 1
#define HAVE_SYS_TIME_H 1
then the two versions you have are equivalent, but
if it has done
#define TIME_WITH_SYS_TIME
#define HAVE_SYS_TIME_H
then only the #if defined(...) versions are valid C.
The convention in autoconf etc. is to either
#define X 1 or #undef X for each variable X.
Russ
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] PCC - #if
2007-05-04 21:17 ` Russ Cox
@ 2007-05-04 21:35 ` lucio
2007-05-04 21:56 ` geoff
2007-05-04 21:57 ` Russ Cox
0 siblings, 2 replies; 6+ messages in thread
From: lucio @ 2007-05-04 21:35 UTC (permalink / raw)
To: 9fans
> The convention in autoconf etc. is to either
> #define X 1 or #undef X for each variable X.
So if I have
#undef C
followed by
#if C
is it valid or invalid? Your explanation leaves it unclear (or I
missed it, somehow).
++L
PS: CPP still needs "elsif" changed to "elif" in the error message.
Shall I submit a patch?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] PCC - #if
2007-05-04 21:35 ` lucio
@ 2007-05-04 21:56 ` geoff
2007-05-04 21:57 ` Russ Cox
1 sibling, 0 replies; 6+ messages in thread
From: geoff @ 2007-05-04 21:56 UTC (permalink / raw)
To: 9fans
No need for a patch; there's updated cpp source on sources now.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] PCC - #if
2007-05-04 21:35 ` lucio
2007-05-04 21:56 ` geoff
@ 2007-05-04 21:57 ` Russ Cox
1 sibling, 0 replies; 6+ messages in thread
From: Russ Cox @ 2007-05-04 21:57 UTC (permalink / raw)
To: 9fans
> So if I have
>
> #undef C
>
> followed by
>
> #if C
>
> is it valid or invalid? Your explanation leaves it unclear (or I
> missed it, somehow).
It is valid. `#if C' macro-expands to `#if C' (no change)
and then all names in #if expressions turn into 0s, so it
is treated as `#if 0'.
Russ
^ permalink raw reply [flat|nested] 6+ messages in thread
* [9fans] PCC - #if
@ 2007-05-04 20:32 lucio
0 siblings, 0 replies; 6+ messages in thread
From: lucio @ 2007-05-04 20:32 UTC (permalink / raw)
To: 9fans
I have the following diff:
term% diff ../../../openldap-2.3.32/include/ac/time.h ../../include/ac
20c20
< #if defined(TIME_WITH_SYS_TIME)
---
> #if TIME_WITH_SYS_TIME
23c23
< #elif defined(HAVE_SYS_TIME_H)
---
> #elif HAVE_SYS_TIME_H
and I'm curious whether it's a slip in the OpenLDAP source or in PCC
that the one works and the other doesn't. I do not have an ANSI
standard to check against, but my gut feel is that OpenLDAP is
stretching a limit. If not, then PCC ought to be corrected, it
reports (the "elsif" is certainly mistaken):
cpp: ../../include/ac/time.h:20 csn.c:47 Syntax error in #if/#elsif
++L
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-05-04 21:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-04 20:23 [9fans] PCC - #if lucio
2007-05-04 21:17 ` Russ Cox
2007-05-04 21:35 ` lucio
2007-05-04 21:56 ` geoff
2007-05-04 21:57 ` Russ Cox
2007-05-04 20:32 lucio
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 NNTP newsgroup(s).