How do I declare __sync_fetch_and_add?

I am writing a program that could very much use __sync_fetch_and_add. Unfortunately my autoconf script that searches for it with this fairly straightforward test:


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 super-annoying, because I would like to use the function, but some people on some platforms have told me that it doesn't compile properly. I want a prototype, but there doesn't seem to be one.


-------------Problems Reply------------

AC_CHECK_FUNCS is not usable in this case, since redeclarating the function — which autoconf does (char functionthatiwant() in conftest.c/config.log) — will override the builtin function detrimentally. You would need something like the following instead.

AC_MSG_CHECKING([for __sync_fetch_and_add])
int main(void) { return __sync_fetch_and_add((int *)0, 0); }

Category:gcc Views:0 Time:2012-02-23

Related post

  • How do I declare a list of fixed length in specman? 2008-08-21

    In E (specman) I want to declare variables that are lists, and I want to fix their lengths. It's easy to do for a member of a struct: thread[2] : list of thread_t; while for a "regular" variable in a function the above doesn't work, and I have to do

  • Why can't I declare static methods in an interface? 2008-08-22

    The topic says the most of it - what is the reason for the fact that static methods can't be declared in an interface? public interface ITest { public static String test(); } The code above gives me the following error (in Eclipse, at least): "Illega

  • Best Practice: Initialize class fields in constructor or at declaration? 2008-08-23

    I've been programming in C# and Java recently and I am curious what people would consider the best practice concerning when you should initialize your classes fields? Should you do it at declaration?: public class Dice { private int topFace = 1; priv

  • How do I fix "for loop initial declaration used outside C99 mode" GCC error? 2008-08-24

    I'm trying to solve the 3n+1 problem and I have a for loop that looks like this: for(int i = low; i <= high; ++i) { res = runalg(i); if (res > highestres) { highestres = res; } } Unfortunately I'm getting this error when I try to compile with G

  • Using .NET CodeDOM to declare and initialize a field in one statement 2008-08-27

    I want to use CodeDOM to both declare and initialize my static field in one statement. How can I do this? // for example public static int MyField = 5; I can seem to figure out how to declare a static field, and I can set its value later, but I can't

  • How to declare an array of strings in C++? 2008-08-29

    I am trying to iterate over all the elements of a static array of strings in the best possible way. I want to be able to declare it on one line and easily add/remove elements from it without having to keep track of the number. Sounds really simple, d

  • Why can't a forward declaration be used for a std::vector? 2008-09-01

    If I create a class like so: // B.h #ifndef _B_H_ #define _B_H_ class B { private: int x; int y; }; #endif // _B_H_ and use it like this: // main.cpp #include <iostream> #include <vector> class B; // Forward declaration. class A { public:

  • function declaration isn't a prototype 2008-09-03

    I have a library I created, mylib.c: #include <mylib.h> int testlib() { printf("Hello world\n"); return (0); } mylib.h: #include <stdio.h> extern int testlib(); In my program, I've attempted to call this library function: myprogram.c: #in

  • How to deal with arrays (declared on the stack) in C++? 2008-09-10

    I have a class to parse a matrix that keeps the result in an array member: class Parser { ... double matrix_[4][4]; }; The user of this class needs to call an API function (as in, a function I have no control over, so I can't just change its interfac

  • Regex that Will Match a Java Method Declaration 2008-09-16

    I need a Regex that will match a java method declaration. I have come up with one that will match a method declaration, but it requires the opening bracket of the method to be on the same line as the declaration. If you have any suggestions to improv

  • Does the DOCTYPE declaration have to be the first tag in an HTML document? 2008-09-16

    Our security manager dynamically inserts a bit of javascript at the top of every html page when a page is requested by the client. It is inserted above the DOCTYPE statement. I think this might be the cause of the layout problems I am having. Ideas a

  • Visual Basic 6.0 to VB.NET declaration 2008-09-16

    How do I declare "as any" in VB.NET, or what is the equivalent? --------------Solutions------------- VB.NET does not support the as any keyword, VB.NET is a strongly typed language, you can however (with .NET 3.5) use implicit typing in VB Dim fred =

  • What happens to global variables declared in a DLL? 2008-09-16

    Let's say I write a DLL in C++, and declare a global object of a class with a non-trivial destructor. Will the destructor be called when the DLL is unloaded? --------------Solutions------------- In a Windows C++ DLL, all global objects (including sta

  • Best way to access table instances when using SQLAlchemy's declarative syntax 2008-09-16

    All the docs for SQLAlchemy give INSERT and UPDATE examples using the local table instance (e.g. tablename.update()... ) Doing this seems difficult with the declarative syntax, I need to reference Base.metadata.tables["tablename"] to get the table re

  • When should a class member be declared virtual (C#)/Overridable (VB.NET)? 2008-09-17

    Why wouldn't I choose abstract? What are the limitations to declaring a class member virtual? Can only methods be declared virtual? --------------Solutions------------- An abstract method or property (both can be virtual or abstract) can only be decl

  • In ColdFusion 8, can you declare a function as private using cfscript? 2008-09-17

    Normally you create a function using cfscript like: <cfscript> function foo() { return "bar"; } </cfscript> Is there a way to declare this as a private function, available only to other methods inside the same cfc? I know you can do it wi

  • How do you read C declarations? 2008-09-18

    I have heard of some methods, but none of them have stuck. Personally I try to avoid complex types in C and try to break them into component typedef. I'm now faced with maintaining some legacy code from a so called 'three star programmer', and I'm ha

  • Why can't variables be declared in a switch statement? 2008-09-18

    I've always wondered this - why can't you declare variables after a case label in a switch statement? In C++ you can declare variables pretty much anywhere (and declaring them close to first use is obviously a good thing) but the following still won'

  • Variable declarations in header files - static or not? 2008-09-18

    When refactoring away some #defines I came across declarations similar to the following in a C++ header file: static const unsigned int VAL = 42; const unsigned int ANOTHER_VAL = 37; The question is, what difference, if any, will the static make? Not

Copyright (C), All Rights Reserved.

processed in 0.154 (s). 11 q(s)