home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!utcsri!dgp.toronto.edu!flaps
- Newsgroups: comp.std.c
- From: flaps@dgp.toronto.edu (Alan J Rosenthal)
- Subject: Re: struct hack, and other out-of-array references
- Message-ID: <1992Sep12.164648.10600@jarvis.csri.toronto.edu>
- References: <1992Sep07.104932.20060@x.co.uk> <1992Sep8.124655.1498@Urmel.Informatik.RWTH-Aachen.DE> <1992Sep10.014137.16209@sq.sq.com> <1992Sep10.213240.10272@thinkage.on.ca> <1992Sep11.012438.24377@jarvis.csri.toronto.edu> <9225600.28053@mulga.cs.mu.OZ.AU>
- Date: 12 Sep 92 20:46:48 GMT
- Lines: 17
-
- fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- >Do same considerations would apply if you tried to use a char[5][5]
- >array as a char[25] array?
-
- Actually, I don't think that they do, because along the path to doing this
- screwing around you go through a (char *).
-
- >From what you're saying, the reason that casting the return
- >value from malloc succeeds is only because malloc is "magic".
-
- I think the magic of pointer-to-char comes into play too. Any object can be
- traversed by pointers-to-char. So in your example, in my opinion, you're ok
- because the dubious operation occurs with pointers-to-char.
-
- Note that you're even guaranteed that the "sizeof" of a char[5][5] array is
- exactly 25, because sizeof(char) has to be 1 and an array 5 of something has to
- be exactly 5 times the "sizeof".
-