[comp.std.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

diamond@jit345.swstokyo.dec.com (Norman Diamond) (04/08/91)

In article <13698@adobe.UUCP> taft@adobe.COM writes:
>  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.
Mine too.  (Personal opinion.)

>This compiler does not claim to be ANSI-compliant,
>but it does support the volatile type qualifier
[Two incorrect warning messages.]
The warnings give the impression that it does not support volatile ... but ...
>The correct code appears to be generated in spite of the warnings.
... ah, so it does support volatile (as far as you and I know so far).

>Is the compiler wrong to complain about this usage,

An ANSI-compliant compiler may give any spurious error messages that it
wishes, as long as it correctly processes a strictly conforming program.
So, even an ANSI-conforming compiler could give the two incorrect warnings
that you quoted.

A non-ANSI-conforming compiler can do whatever it wants.

This non-ANSI-conforming compiler seems to come fairly close to conforming.

In both cases, quality of implementation is different from requirements.
If you tell your vendor that their product has an error, they might agree.
(Sorry, I don't know how to maximize the chance that they will agree.)

>or does the program really violate the standard in some way?
As far as I can see, the program does not violate the standard.
--
Norman Diamond       diamond@tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.