Re: [Jack-Devel] Alignment (again)
Gabriel Beddingfield wrote:
> I ran into a strange bug where the conclusion was that:
>
> float *buf = malloc(512*sizeof(float));
>
> Is invalid/undefined code. I don't have a copy of the C spec, but the
> C++ spec says, that since a `float` must be 4-byte aligned... so must a
> `float*`.[1] However, malloc(3) has no alignment requirements.
C99 7.20.3 says:
| The pointer returned ... is suitably aligned so that it may be
| assigned to a pointer to any type of object and then used to access
| such an object or an array of such objects in the space allocated ...
Anything else would not make sense.
> eglibc returns an arbitrary alignment.
On architectures where alignment matters, this would be a horrible bug
in eglibc.
Regards,
Clemens
1312438517.816_0.ltw:2,a <4E3A39AF.6070707 at ladisch dot de>