expr?(void):(void) WHY I THINK IT'S *OK* ( or should be )

Ray Butterworth rbutterworth at watmath.UUCP
Fri Aug 8 00:34:31 AEST 1986


> Lint obviously does *some* analysis of this, since it can say
> "constant in conditional context". BTW, I have a program that gives
> that error, but the expression is in an ARRAY DIMENSION for crissake.
>         char foo[ THING1 > THING2 ? THING1 : THING2 ];
> Obviously it's going to be a constant. Any lint authors listening?
> Turn that off when a constant expression is called for. While I'm
> wishing for things, I wanna see 'assignment in conditional context'.
> We all know why by now...


------/usr/src/lib/mip/cgram.y------(look for "con_e:")

/*    EXPRESSIONS    */
con_e:        {
#ifdef LINT
                {extern int constexp;}
                constexp=1;
#endif
                $<intval>$=instruct; stwart=instruct=0;
            } e
            %prec CM
            ={
                $$ = icons( $2 );
                instruct=$<intval>1;
#ifdef LINT
                constexp=0;
#endif
            }
        ;
.e:           e


------/usr/src/lib/mip/trees.c------(look for warning message)

    case BRANCH:
    ccwarn:
#ifdef LINT
        {extern int constexp;}
        if (hflag&&!constexp)
            werror("constant in conditional context");
#endif
    case PLUS:


------/usr/src/usr.bin/lint/lpass1.c------(add to definitions of externals)

int constexp=0;


------/usr/src/usr.bin/lint/lpass1.c------(in function contx())

contx( p, down, pl, pr ) register NODE *p; register *pl, *pr; {

    *pl = *pr = VAL;
    if (p->in.type==UNDEF) down=VAL; /* (void) cast */

    switch( p->in.op ){

    case NOT:
        *pl=down;
    case ANDAND:
    case OROR:
        if (hflag&&(p->in.right->in.op==ASSIGN))
            werror("Possible unintended assignment");
    case QUEST:
        *pr = down;
    case CBRANCH:
        if (hflag&&(p->in.left->in.op==ASSIGN))
            werror("possible unintended assignment");
        break;

    case SCONV:
    case PCONV:



More information about the Comp.lang.c mailing list