the "const" qualifier

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Aug 5 11:11:53 AEST 1990


In article <1990Aug2.011735.1143 at ccu.umanitoba.ca> rpjday at ccu.umanitoba.ca writes:
>  const struct s { int mem ; } cs = { 1 } ;
>  struct s ncs ;
>  int *pi;
>  pi = &cs.mem;   /* violates type constraints for = */
>Now I can appreciate that the assignment to "pi" should not be allowed,
>but PRECISELY which rule makes this illegal?

Supposedly the constraint in 3.3.16.1 that requires the thing pointed to
by the LHS to have all the qualifiers of the thing pointed to by the RHS
is violated.  For this to work, the "mem" member of the struct "cs" must
also be considered to be const-qualified, which is reasonable but hard
to deduce from the wording in the standard.  Basically, all parts of an
object declared with a type qualifier are also so qualified.

>  ncs = cs ;      /* valid */
>I know it's totally harmless, but "ncs" and "cs" have different
>qualification, so does that make them different types?)

No constraint is violated by this assignment.



More information about the Comp.std.c mailing list