Is there a way to ignore return values ββin Ada functions?
I have a function that imports from Intrinsic.
subtype int32 is Interfaces.Interger_32; function Intrinsic_Sync_Add_And_Fetch (P : access int32; I : int32) return int32; pragma Import( Intrinsic, Intrinsic_Sync_Add_And_Fetch, "__sync_add_and_fetch_4");
If I want to use this in the procedure, I need to accept the return value or I will get a compiler error:
cannot use function Intrinsic_Sync_Add_And_Fetch in procedure call.
But if I create a variable that simply takes the return value of the function and is never used, I get compiler warnings. Obviously, I would rather avoid this.
I cannot properly assign a value to the return value that I am adding; this would undermine the point of the add operation, which is atomic.
There is the ability to take value and do something like it:
val := Intrinsic_Sync_Add_And_Fetch(...); if val := 0 then null; end if;
This makes the code compile without errors or warnings, but it seems to me that this is stupid. How can I get around this language feature and safely ignore the return value?
Edit: what is __sync_add_and_fetch_4?
This is an integrated atomic operation available for Intel processors. That way, part of my Autoconf / Automake process will decide if an operation is available and use a fallback implementation that includes a critical section if it is not.
You can read about this and similar operations in the GCC section for atomic inline functions .
__sync_add_and_fetch_4 does pretty much what it says. In C it will look something like this:
int32_t __sync_add_and_fetch_4(int32_t *ptr, int32_t value) { *ptr += value; return *ptr; }
So, this is an atom addition operation that returns the result of an addition. In principle, this is the atomic operator += . _4 means that it takes an integer of 4 bytes.
Change I understand that I could just turn off this compiler warning, but that always seems dirty to me. If there is a solution available that allows me to continue using -Wall -Werror , then I would really like to see it.