[comp.lang.c] volatile and typedef

taft@adobe.com (Ed Taft) (04/07/91)

Consider the following example:

  typedef int *int_ptr;
  int_ptr pi;
  volatile int_ptr vpi;

  int test()
  {
    vpi = pi;
    return *vpi;
  }

My understanding is that the volatile type qualifier refers only to the
variable vpi (used as an lvalue) and not to the thing it points to. I base
this on the example given in 3.5.4.1, although that example uses const
instead of volatile.

Unfortunately, the C compiler on the DECstation 5000 (Ultrix 4.0) apparently
thinks otherwise. This compiler does not claim to be ANSI-compliant, but it
does support the volatile type qualifier out of necessity. Here are its
complaints:

ccom: Warning: volatile.c, line 8: illegal pointer combination
        vpi = pi;
      ----------^
ccom: Warning: volatile.c, line 9: illegal combination of pointer and
integer, op RETURN
        return *vpi;
      -------------^

The correct code appears to be generated in spite of the warnings. In
contrast to this, gcc accepts the above program without complaint (even with
-Wall and -pedantic options). I also cannot get the Ultrix compiler to
generate any complaints unless a typedef is involved.

Is the compiler wrong to complain about this usage, or does the program
really violate the standard in some way?


Ed Taft      taft@adobe.com      ...decwrl!adobe!taft