How to declare __sync_fetch_and_add?

I am writing a program that can use __ sync_fetch_and_add very heavily. Unfortunately, my autoconf script that searches for it with this rather simple test:

 AC_CHECK_FUNCS([__sync_fetch_and_add]) 

Generates this error:

 Wsuggest-attribute=noreturnconftest.c:56:1: warning: function declaration isn't a prototype [-Wstrict-prototypes] conftest.c:56:6: warning: conflicting types for built-in function '__sync_fetch_and_add' [enabled by default] conftest.c:65:1: warning: function declaration isn't a prototype [-Wstrict-prototypes] /tmp/ccqPsZz4.o: In function `main': /home/simsong/domex/src/bulk_extractor/tags/1.2.x/conftest.c:67: undefined reference to `__sync_fetch_and_add' collect2: ld returned 1 exit status 

This is very annoying because I would like to use this feature, but some people on some platforms told me that it does not compile properly. I want a prototype, but it seems not one.

Thanks.

+4
source share
1 answer

AC_CHECK_FUNCS not applicable in this case, since overriding the function that autoconf does ( char functionthatiwant() in conftest.c / config.log ) will override the built-in function to the detriment. Instead, you'll need something like the following.

 AC_MSG_CHECKING([for __sync_fetch_and_add]) AC_LINK_IFELSE( [AC_LANG_SOURCE([ int main(void) { return __sync_fetch_and_add((int *)0, 0); } ])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])] ) 
+4
source

Source: https://habr.com/ru/post/1397952/


All Articles