Help, page 197 K&R !!!

Phil Cornes pc at cs.keele.ac.uk
Fri Jun 30 23:46:06 AEST 1989


>From article <646 at kl-cs.UUCP>, by atula at cs.keele.ac.uk (Atula Herath):
> Could somebody please explain me follwing para, from the K&R.
> 
> Page 197, para 7 :
> 
> What does that mean ?
> 

This is a paragraph in the 1st edition K&R. The paragraph details a restriction
on the choice of member names in structures and unions. The restriction itself
is fairly easy to understand, though most C compilers now available don't 
enforce it so it is not as easy to demonstrate.

K&R C says that member names in structures and unions must (in general) be
unique. This is because in early implementations the names of structure and
union members were not associated with their parent names, but were only stored
as a type and offset from the start of the parent. Attempting to use the same
member name in two places would therefore usually involve trying to assign two
different type and offset values to that name (clearly not allowed). Page 197
para 7 however, goes on to say that if using the name in two places would lead
to the same type and offset values being allocated for both then this is okay.

Most current K&R compilers and ANSI compilers don't have this problem because
they associate parent names with member names, thus automatically making unique
names out of each member name so that the same member name may appear in more
than one place (though obviously not twice within the same struct or union).

---

Phil Cornes
-----------*
cdtpc at uk.ac.stafpol.cr83

---



More information about the Comp.lang.c mailing list