4
votes

I am using a structure

typedef struct ObjectHandle
{
    long *objHandle;
}ObjectHandle ;

A function where the output is the value of this structure

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

But compiler is giving warning: assignment makes pointer from integer without a cast

Please help

3

3 Answers

7
votes

Seems like you're assigning the value not to the value (memory), but to a pointer (address)

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

0
votes

Since It is a long pointer it should have address of long variable.

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

You're assigning a long integer to a pointer (objHandle is a pointer to a long). Just like the compiler says.

This is valid c but generally a rather silly thing to do as long integers are long integers, not pointers.

Without seeing what the "some long value" actually refers to, and how the handle is subsequently used, it's a little difficult to indicate whether you should be casting the value, taking the address of it, changing the type of the handle, or something else.