Assignment makes a pointer from a whole without cast C

I use structure

typedef struct ObjectHandle { long *objHandle; }ObjectHandle ; 

Function in which the output is the value of this structure

 AllocateObject(ObjectHandle* objectHandle) { .... ... ... objectHandle->objHandle = some long value; } 

But the compiler gives a warning: assignment makes a pointer from an integer without cast

Please, help

+4
source share
3 answers

It looks like you are assigning a value not to a value (memory), but to a pointer (address)

Try the following: *(objectHandle->objHandle) = some long value;

+7
source

Since this is a long pointer, it must have the address of a long variable.

 objectHandle->objHandle = &(some long value); 
0
source

You assign a long integer to a pointer (objHandle is a pointer to a long one). Just like the compiler says.

This is valid c, but this is usually a pretty dumb thing, since long integers are long integers, not pointers.

Not seeing what โ€œsome kind of long valueโ€ really means, and how this descriptor is used, itโ€™s a little difficult to indicate whether the value should be distinguished by accepting its address, changing the type of the descriptor, or something else.

0
source

Source: https://habr.com/ru/post/1485375/


All Articles