diff --git a/include/asterisk/compat.h b/include/asterisk/compat.h
index ced14fc41bcc806df512399493c4f874e12b93a0..0dd3685d61c2489a36c23f95808f002aca3fc502 100644
--- a/include/asterisk/compat.h
+++ b/include/asterisk/compat.h
@@ -52,9 +52,14 @@
 #endif
 
 #ifdef HAVE_ALLOCA_H
-#include <alloca.h>	/* not necessarily present - could be in stdlib */
-#elif defined(HAVE_ALLOCA)
-#include <malloc.h>	/* see if it is here... */
+#include <alloca.h>
+#elif defined(__GNUC__)
+#define alloca __builtin_alloca
+#elif defined(_AIX)
+#define alloca __alloca
+#elif defined(_MSC_VER)
+#include <malloc.h>
+#define alloca _alloca
 #endif
 
 #include <stdio.h>	/* this is always present */