Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: the "const" qualifier Message-ID: <13475@smoke.BRL.MIL> Date: 5 Aug 90 01:11:53 GMT References: <1990Aug1.005200.21645@ccu.umanitoba.ca> <13462@smoke.BRL.MIL> <1990Aug2.011735.1143@ccu.umanitoba.ca> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 20 In article <1990Aug2.011735.1143@ccu.umanitoba.ca> rpjday@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.