0

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?

2
  • 3
    If you want b to save an address it will need to be the size of an address. Not sure why you would not be using a uint16_t* for b as well: uint16_t* b[4]. Commented Jun 26, 2013 at 16:44
  • If he wants to "save the address of uint16_t *g_00", it should be uint16_t **b[4]; if he wants to save the value of uint16_t *g_00, it should be uint16_t *b[4]. If you want b to save a pointer it will need to be an array of objects with the same type as the pointers, not just the same size as the pointers; except for void *s, C pointers aren't generic addresses, they're pointers to particular types. Commented Jun 26, 2013 at 17:47

1 Answer 1

2

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. */
Sign up to request clarification or add additional context in comments.

5 Comments

As "the address of uint16_t *g_00" is a pointer to a pointer to a uint16_t, presumably you meant uint16_t **b[4].
Mathuin's edit is plain wrong. However I cannot undo it now and here!
@guyharris: It wasn't me <tm>!
Well, I don't know why you couldn't edit your own answer, but it appears that I can, so I just edited it to be correct. (For anybody who's tempted to remove one of those *s, say to yourself "in C, arrays are not pointers" before succumbing to temptation.)
@guyharris: Thx! I want to rollback not just edit the edit ... and was lost on my micro- mobile's micro display S-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.