Path: utzoo!utgpu!water!watmath!clyde!att!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.lang.c Subject: Re: sizeof( _variable_ ) Message-ID: <6089@chinet.chi.il.us> Date: 24 Jul 88 20:24:25 GMT References: <1264@bc-cis.UUCP> <529@proxftl.UUCP> Reply-To: les@chinet.chi.il.us (Leslie Mikesell) Distribution: na Organization: Chinet - Public Access Unix Lines: 19 In article <529@proxftl.UUCP> bill@proxftl.UUCP (T. William Wells) writes: >:..... I should think that sizeof( _variable_ ) >: should be the length of the _variable_ not the length of the memory allocated >: to it. >What is happening is this: C defines the size of a type as if it >were part of an array. The point of this is that you can access corresponding elements of successive structures in an array by adding sizeof(struct) to a pointer to the previous element. If sizeof(struct) did not include the padding there would be no way to find the next corresponding element from the address of the previous, and loops accessing one element of each struct in an array would have to be written in a less efficient way (and you might have to deal with pointers to structs and the necessity of casting them for most operations instead of using pointers to the data type of the element you are accessing). Les Mikesell