This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
is it possible to size a pointer's target?
- From: "Andrew Ross" <grof at rogers dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Sat, 22 Sep 2007 00:11:41 -0400
- Subject: is it possible to size a pointer's target?
Hi Everyone,
I'm interested in whether it is possible to get the size of a variable a
pointer is pointing at.
I have a function that accepts a char * pointer. This can either be stack or
heap memory but more typically stack where I see it.
It would help me tremendously if I could figure out the size of the variable
at the other end of the pointer. I can't think of a way to do this
unfortunately.
strlen won't work as the variable is null when passed in
sizeof(*ptr) returns 1, even though the memory is larger
sizeof(ptr) returns 4 (on my 32 bit machine) of course
Can anyone think of how to do this, or am I out of luck?
Thank you in advance,
Andrew