[9fans] PCC - #if - Plan9

This is a discussion on [9fans] PCC - #if - Plan9 ; I have the following diff: term% diff ../../../openldap-2.3.32/include/ac/time.h ../../include/ac 20c20 --- > #if TIME_WITH_SYS_TIME 23c23 --- > #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 ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: [9fans] PCC - #if

  1. [9fans] PCC - #if

    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


  2. Re: [9fans] PCC - #if

    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


  3. Re: [9fans] PCC - #if

    > 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?


  4. Re: [9fans] PCC - #if

    > 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


  5. Re: [9fans] PCC - #if

    No need for a patch; there's updated cpp source on sources now.


+ Reply to Thread