michael
michael

Reputation: 110670

How to fix compiler error ': warning: assignment makes integer from pointer without a cast'

My code below gives me a warning:

warning: assignment makes integer from pointer without a cast":

uint16_t b[4];
uint16_t *g_00;
uint16_t *g_01;
uint16_t *g_10;
uint16_t *g_11;


b[0] = g_00;
b[1] = g_01;
b[2] = g_10;
b[3] = g_11;

printf ("add = %x\n", b[0]);

I meant to use b[0]... b[1] to save the address of uint16_t *g_00;

How can I fix this compiler warning?

Upvotes: 0

Views: 212

Answers (1)

alk
alk

Reputation: 70981

I meant to use b[0]... b[1] to save the address of uint16_t *g_00;

To store addresses in b's entries, you need to declare it as array of pointers:

uint16_t ** b[4];

uint16_t * g_00;
...

b[0] = &g_00; /* Stores g_00's address. */

Update:

The OP's statement:

b[0] = g_00;

does not store the address of g_00 but the value carried by g_00 itself.

If this was the intend (in contrast to storing g_00' address), the correct declaration of b would be:

uint16_t * b[4];

uint16_t * g_00;
...

b[0] = g_00; /* Stores g_00's value. */

Upvotes: 2

Related Questions