Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site watmath.UUCP
Path: utzoo!watmath!kpmartin
From: kpmartin@watmath.UUCP (Kevin Martin)
Newsgroups: net.lang.c
Subject: Re: A useful construct for C ?
Message-ID: <11401@watmath.UUCP>
Date: Sat, 9-Feb-85 16:30:38 EST
Article-I.D.: watmath.11401
Posted: Sat Feb  9 16:30:38 1985
Date-Received: Sun, 10-Feb-85 06:38:03 EST
References: <389@lll-crg.ARPA> <8095@brl-tgr.ARPA>
Reply-To: kpmartin@watmath.UUCP (Kevin Martin)
Organization: U of Waterloo, Ontario
Lines: 25
Summary: 

>> It would be nice to be able to say:
>> 	int *foo;
>> 	foo = (typeof(foo))malloc(sizeof(*foo) * nelts);
>
>Actually, MALLOC really should know what alignment requirement is
>required.  Right now it just takes the least common multiple of
>all data types.  Should a similar builtin function (I'll use a
>silly name here to avoid confusion:
>
>	foo = (typeof foo) malloc(sizeof(*foo)*nelts, rons_typeof foo);
>
>Where rons_typeof would yield something like an enum that could be checked
>for in the Malloc routine.
>
>-Ron


This sounds like a job for an 'alignof' operator:
    foo = (typeof foo) malloc(sizeof(*foo)*nelts, alignof(*foo) );

In addition, several implementations require a method of finding the
alignment of a type in order to implement  (or ,
depending who you ask).
               Kevin Martin, UofW Software Development Group