chasep255
chasep255

Reputation: 12175

GCC incompatible pointer type warning with intrinsic functions

The type of a->data is uint64_t *. I looked it up in the header file and uint64_t is defined as unsigned long int. I want to use the _addcarryx_u64 function. The last parameter of this function according to the header file is of type unsigned long long *.

In both are unsigned 64 bit integers. However technically they are different and I keep getting annoying warnings like this...

warning: passing argument 4 of ‘_addcarryx_u64’ from incompatible pointer type

char c = _addcarryx_u64(0, a->data[0], b, a->data);

How can I either fix this or disable the warning. I know I could cast my pointer but I like to code in a somewhat compile independent manner and addcarryx could be defined differently on another system.

Also on a side note I noticed that my gcc version only supports addcarryx and not plain addcarry. Any reason why?

Also just so you know I am running GCC 4.9 compiling on ubuntu. I have -std=gnu99 set.

Upvotes: 2

Views: 235

Answers (1)

Filipe Gonçalves
Filipe Gonçalves

Reputation: 21213

If you don't want to cast, I suggest you write your own wrapper function that converts a->data to the correct type and then passes a pointer to that:

struct a_struct {
    /* ... */
    uint64_t *data;
};

char addcarry_u64(int x, struct a_struct *a, int b) {
    unsigned long long data = *a->data;
    return _addcarryx_u64(0, a->data[0], b, &data);
}

Upvotes: 2

Related Questions