volatiles/consts inside structs in dpANS C

Dale Hagglund rdh at myrias.UUCP
Thu Mar 3 22:36:58 AEST 1988


What does the draft Standard have to say about a structure declared as

        struct {
            const int x;
            int y;
            double z;
        } s1, s2;

Are s1 and s2 constant structures, non-constant structures, or are they
something sort of in between?

If they are constant structures, then

	s1.y = s2.y;

becomes illegal, which seems sort of odd. However, if they are not
constant, then

	s1 = s2;

should be legal.  This is equivalent (it is equivalent, right?) to

	s1.x = s2.x;
	s1.y = s2.y;
	s1.z = s2.z;

Unfortunately, the first assignment here is illegal, since s1.x is a
constant field.

I have been looking at my copy of the draft Standard (November 9,
1987), but it doesn't seem to say anything about this particular kind
of declaration.  Section 3.5.3, "Type qualifiers," says only that
members of qualified aggregates or unions have the "equivalently
qualified" types.  It says nothing about whether or not qualification
moves up from aggregate members to aggregates.

So, what's the answer?  Is structure assignment disallowed for those
structs containing const fields, or does the struct assignment just
assign across the non-const fields, making

	s1 = s2;

equivalent to

	s1.y = s2.y;
	s1.z = s2.z;

and just leaving s1.x alone?

Similar sorts of weirdness arise when you replace "const" with
"volatile" in the declaration of s1 and s2 above.  I would appreciate
any comments on just what these sorts of declarations mean, or if they
mean anything at all, either via email or on the net.

Thanks in advance,
	Dale.
--
Dale Hagglund        Phone: (403) 428-1616        UUCP: ...!alberta!myrias!rdh
Myrias Research Corp., 900 - 10611 98th Ave, Edmonton, Alberta, Canada T5K 2P7
-- 
--
Dale Hagglund        Phone: (403) 428-1616        UUCP: ...!alberta!myrias!rdh
Myrias Research Corp., 900 - 10611 98th Ave, Edmonton, Alberta, Canada T5K 2P7



More information about the Comp.lang.c mailing list