Printing the address of a struct object
Posted
by bdhar
on Stack Overflow
See other posts from Stack Overflow
or by bdhar
Published on 2010-06-14T06:56:27Z
Indexed on
2010/06/14
7:02 UTC
Read the original article
Hit count: 247
I have a struct
like this
typedef struct _somestruct {
int a;
int b;
}SOMESTRUCT,*LPSOMESTRUCT;
I am creating an object for the struct
and trying to print it's address like this
int main()
{
LPSOMESTRUCT val = (LPSOMESTRUCT)malloc(sizeof(SOMESTRUCT));
printf("0%x\n", val);
return 0;
}
..and I get this warning
warning C4313: 'printf' : '%x' in format string conflicts with argument 1 of type 'LPSOMESTRUCT'
So, I tried to cast the address to int
like this
printf("0%x\n", static_cast<int>(val));
But I get this error:
error C2440: 'static_cast' : cannot convert from 'LPSOMESTRUCT' to 'int'
What am I missing here? How to avoid this warning?
Thanks.
© Stack Overflow or respective owner