home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.std.c++:1830 comp.std.c:3227
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!olivea!charnel!rat!usc!howland.reston.ans.net!europa.asd.contel.com!emory!gwinnett!amfent!amf
- From: amf@amfent.Gwinnett.COM (Andy Feibus)
- Newsgroups: comp.std.c++,comp.std.c
- Subject: Re: Question about sizeof in C/C++.
- Message-ID: <wwJXVB3w164w@amfent.Gwinnett.COM>
- Date: 17 Dec 92 14:10:55 GMT
- References: <jamesc.724544278@bart>
- Lines: 18
-
- jamesc@swapsdev.state.state.COM.AU (James Cribb) writes:
- > Given
- >
- > struct Something* ps;
- > unsigned k;
- >
- > do the C or C++ standards guarantee that
- >
- > &ps[k] == ((char*) ps) + k * sizeof(struct Something)
- >
- > I'm asking because I have C++ code that relies on this.
- > It works on Suns but is it portable?
- Assuming that you [cm]alloc enough memory for ps to support accessing the
- k'th element of it, the answer is... no. Different compilers see &ps[k]
- differently; use parentheses to clarify: &(ps[k]).
-
- -- Andy.
- andyfe@utoday.com
-