Re: [Jack-Devel] Alignment (again)

PrevNext  Index
DateThu, 04 Aug 2011 08:18:23 +0200
From Clemens Ladisch <[hidden] at ladisch dot de>
ToGabriel Beddingfield <[hidden] at gmail dot com>
Cc[hidden] at lists dot jackaudio dot org
In-Reply-ToGabriel Beddingfield [Jack-Devel] Alignment (again)
Follow-UpGabriel Beddingfield 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
PrevNext  Index

1312438517.816_0.ltw:2,a <4E3A39AF.6070707 at ladisch dot de>