This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: __alignof__(void)
- To: Mike Stump <mrs at wrs dot com>, law at cygnus dot com
- Subject: Re: __alignof__(void)
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Thu, 10 Sep 1998 11:07:50 +0100
- CC: egcs at cygnus dot com
- Organization: Computer Science Dept, Bristol University
- References: <199809100007.RAA27749@kankakee.wrs.com>
Mike Stump wrote:
> > From: Nathan Sidwell <nathan@acm.org>
> > What is a desirable value for __alignof__(void) to return?
>
> > IMHO a useful value to return would be the maximum alignment for any
> > type.
>
> There are three possibilities, 0, 1, or the above. The above is
> really many different values, the maximum alignment of any ANSI C
> named type, any regular GNU named type, any possibly named type, and
> the maximum alignment permitted by the executable format. The last is
> subject to change overtime, and hence, isn't a good value for any
> portable program to ever see or know. Also, do you count types like
> int __attribute__((__mode__(__OI__))), even though the don't have
> names and are poorly supported and can't be aligned by the object file
> format?
>
> I distinctly don't like the last possibility. 0 or 1 is fine. 1 is
> surprising generally, but if you buy into sizeof(void)==1, then it is
> less so.
Thanks for your thoughts.
There is a fourth possibility -- error!
Thanks for pointing out that `maximum alignment' can be ambiguous --
especially for those weird types. For the record what I'm suggesting is
the smallest alignment which is acceptable for all objects --
BIGGEST_ALIGNMENT / BITS_PER_INT. I don't mean the largest alignment you
can specify in the object file. My knowledge of gcc's
__attribute__((__mode__(__OI__)) stuff is small, so I don't know what
that means. However, reading the doc's implies BIGGEST_ALIGNMENT is all
that's needed. The compilation system must know this value, otherwise it
cannot provide malloc().
I had thought about the sizeof(void) == 1 issue. Both are singularities
in the type system, and I'm not sure what `consistent' means in this
case. I suppose if __alignof__ gives the maximal alignment, sizeof
should give the largest size (but let's not go down that road). The
values 0 and 1 don't provide any information, what I'm suggesting does.
Jeffrey A Law wrote:
> Interesting idea. I've got no particular objection if the langauge
> lawyer types think it's reasonable and there's no upcoming standard
> that will define an alignof operator (can someone check c9x? to see
> if they've added anything like alignof?)
The c9x draft dated 1997-11-21 doesn't mention an alignof unary
operator, or equivalent. Ergo, we're ok to do what we want.
Applogies in advance, if I'm slow responding to further comments. I'm on
vacation next week.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk