🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1858

Alignment requirements

#1858
From: Bob Kline
Date: Mon, 28 Aug 1995 16:52
41 lines
2356 bytes
I have found (on more than one occasion) published code which
appears to rely on an assumption about c++ for which I haven't 
been able to find any justification in the ARM or the draft
standard itself.  The assumption is that a static array of
char is guaranteed to be suitably aligned to hold objects of
any types overlaid on the array's space.  Here is an example
from James Coplien's "Advanced C++ Programming Styles and
Idioms" (page 149, ff.):

    unsigned char bigBuf[4096], *bigBufPtr = bigBuf;

    class LAPD {
    public:
        void *operator new(size_t) { return (void *)bigBufPtr; }
        ...
    };

The details of the class are elided here, but several pages later
the data members are shown to include a couple of pointers, which
(at least on some machines with which I am familiar) would cause
things to blow up if they were not placed on a suitably aligned
memory boundary.

So my question is: does the draft standard require that all arrays
of char be placed by the compiler at an address which would meet
the alignment requirements for any object which might be placed
there?  If so, where should I look in the draft to find this
requirement?


--
/*----------------------------------------------------------------------*/
/* Bob Kline                                       Stream International */
/* bob_kline@stream.com               formerly Corporate Software, Inc. */
/* voice: (703) 522-0820 x-311                      fax: (703) 522-5407 */
/*----------------------------------------------------------------------*/

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <1995Aug28.164444.14306@nlm.nih.gov>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: bkline@cortex.nlm.nih.gov (Bob Kline)
Newsgroups: comp.std.c++
Subject: Alignment requirements
Date: 28 Aug 1995 16:52:39 GMT
Organization: National Library of Medicine
Sender: news@nlm.nih.gov
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <1995Aug28.164444.14306@nlm.nih.gov>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Newsreader: TIN [version 1.2 PL2]
Apparently-To: comp-std-c++@uunet.uu.net
Content-Length: 1549
X-Lines: 37
Originator: clamage@taumet