Article View: comp.std.c++
Article #1282Re: Question about sizeof in C/C++.
From: Andy Feibus
Date: Thu, 17 Dec 1992 14:10
Date: Thu, 17 Dec 1992 14:10
18 lines
967 bytes
967 bytes
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
Technical Details
Message-ID:
<wwJXVB3w164w@amfent.Gwinnett.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sun-barr!ames!olivea!charnel!rat!usc!howland.reston.ans.net!europa.asd.contel.com!emory!gwinnett!amfent!amfReferences:
<jamesc.724544278@bart>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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