Re:Xcode 4 ships a buggy compiler
by psykotic on Friday December 30, 2011 @09:41PM
(#3409938)
Well, alloca is not specified in any formal standard, so you won't find an official ruling on whether it's undefined, unspecified or well-defined. By itself, that state of affairs should strongly discourage its use in portable code.
[ Parent
| on HN ]
At the bottom of my man page:
BUGS
The alloca() function is machine and compiler dependent; its use is dis-
couraged.
Re:Xcode 4 ships a buggy compiler
by FooBarWidget on Saturday December 31, 2011 @04:47AM
(#3410573)
I interpret that statement as it being similar to __asm__(), which is also machine and compiler dependent and discouraged in portable code. Still, sometimes you need it when writing low-level code. __asm__ doesn't blow up the way alloca in the given example does.
Incidentally, I ran into a nasty x64 __asm__ codegen bug with exactly the same compiler version that this blog post covers. It was in lockless multithreaded code, so you can imagine how much fun that was to debug. Rather than work around it, I ended up replacing all our GCC inline assembly with modern intrinsics like __sync_fetch_and_add.