chr-1x / twc

A C99-compatible library for using the Twitter API from cURL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should #include <alloca.h> in addition to #include <malloc.h>

opened this issue · comments

In twitter.c, you should #include <alloca.h> for alloca. I get undefined references to alloca without this when trying to build my program with your library.

└──> dmd -debug -Jres/ blog.d libtwc.a -L-lcurl
libtwc.a(twitter.o): In function 'twc_GenerateOAuthSignature':
/home/mio/scripts/blog/bin/twc/code/twitter.c:700: undefined reference to `alloca'

ketmar tells me this is because of a gcc specific hack that transforms alloca into __builtin_alloca which gets inlined.

Here is a quote from man 3 alloca

Notes on the GNU version
Normally, gcc(1) translates calls to alloca() with inlined code. This is not done when either the -ansi,
-std=c89, -std=c99, or the -std=c11 option is given and the header <alloca.h> is not included. Otherwise,
(without an -ansi or -std=c* option) the glibc version of <stdlib.h> includes <alloca.h> and that contains the
lines:
#ifdef GNUC
#define alloca(size) __builtin_alloca (size)
#endif
with messy consequences if one has a private version of this function.
The fact that the code is inlined means that it is impossible to take the address of this function, or to
change its behavior by linking with a different library.

Thanks for the tip, fixed in referenced commit