From -599589160042457036
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc772,10e355266b6fd117
X-Google-Attributes: gidfc772,public
X-Google-Thread: f78e5,10e355266b6fd117
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-05-28 19:52:11 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!newsxfer.visi.net!news-out.visi.com!hermes.visi.com!feed.news.qwest.net!namche.sun.com!news2me.EBay.Sun.COM!engnews1.eng.sun.com!taumet!clamage
From: Attila Feher <Attila.Feher@lmf.ericsson.se>
Newsgroups: comp.std.c++,comp.lang.c++.moderated
Subject: Re: A humble attempt to suggest alignment support for C++
Date: 29 May 2002 02:42:08 GMT
Organization: Oy L M Ericsson Ab
Lines: 86
Approved: stephen.clamage@sun.com (comp.std.c++)
Message-ID: <3CF3BA36.E792E11@lmf.ericsson.se>
References: <3CEA1A08.C6D95CC7@lmf.ericsson.se>
 <86off0zjam.fsf@alex.gabi-soft.de>
NNTP-Posting-Host: taumet.eng.sun.com
X-NNTP-Posting-Host: netlab.cs.rpi.edu
X-Original-Date: Tue, 28 May 2002 20:11:18 +0300
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated
	iQBVAwUAPPPxW0HMCo9UcraBAQE+CgH9He4YecKw9mjDSSKsQW3vwsS8pKEWKQTK
	VPg9070Ykoq/f6U4ry9J3vgDp+mbLCi0J97Au5uXc7SVI3l080jRbg==
	=LaTm
X-Approved-For-Group: hsutter@acm.org comp.lang.c++.moderated
X-Scanned-By: MIMEDefang 2.3 (www dot roaringpenguin dot com slash mimedefang)
Content-Length: 3723
Originator: clamage@taumet
Xref: archiver1.google.com comp.std.c++:11645 comp.lang.c++.moderated:44096


James Kanze wrote:
[SNIP]
> |>  This solution would enable the coder to change alignment of any  
> |> type or just char arrays in declarations.
> 
> Change, or require?


Yes. :-))))  Change from char alignment requirements to the requirements
of a given type T _or_ require the aligment to be one suitable for the
given type T.  I believe this two means the same.  We are into
linguistics again! :-)))

> I think that g++ has something similar, as an extension.

It does.

> |>  As it seems it is enough for just char arrays, but you may see a  
> |> good reason for open it up to arrays or any other type.
> 
> It's more a question of there not being any reason to restrict it.

Well, I doubt you would want to align and std::string as long double... 
So _if_ it does not make sense, it makes sense to forbid it - since
human errors can be caught this way.  The alignment specification (up to
my knowledge) has one use: to create a buffer suitable for a given type
T.  Now I believe it is unlikely that anyone would like to build such a
buffer on top of any other type than char or maybe unsigned/signed char.
Since the size of the other built in types is implementation defined and
user defined types (the ones with a non-trivial constructor) are usually
not the best candidates for overwriting...

> Orthogonality is a virtue.

I still would like to see any case when it makes any sense.

> |>  It could look something like this:
> 
> |>  align_as<T> char T_arr[sizeof(T)*S];
> 
> |>  So align_as would be a sort of "storage specifier like thing",  
> |> possibly behaving the same as static from syntax point of view.  
> |> Except that it would not "collide" with any storage specifiers,  
> |> since it is a different thing: alignment specifier.

> Well, it probably wouldn't be relevant to allow it on a typedef.

AFAIK static cannot be used in a typedef.  Whether an alignment
specifier should be is a good question.  Probably it would make sense to
be able to define a type alias called bufferForMyTypeBla but in real
life I guess that such a type - or at least its aligment restricted form
- would only be used once.  Either once at all or once inside a template
class as a member.  So I do not see why would anyone want to create a
typedef of it.  Also, to allow it to get into a typedef it should be
part of the type!  Which is just plain wrong - I believe - since there
is absolutely no difference in type between a bunch of characters
forcedly aligned on some boundary (if used as characters) and another
bunch of them which are not aligned _or_ happen to be aligned by
accident.  Of course, I am open for any concrete example where having
alignment requirements "burnt" into a typedef would be useful or
mandatory to achieve something in a real life scenario.

> The fact that g++ has implemented it as an extension means that 1) 
> there is obviously some demand for it, and 2) there is some existing 
> practice.

Yep.  And looking into the compiler generated code (asm) (on SUN, etc.),
it is also obvious that the compilers actually alreday do the "rain
dance of alignment on the stack", so basically everything is there (at
compile and runtime as well!) in every compiler (for a platform with
alignment requirements) to do this.  At least I believe so.

Attila



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]




