E
Evan Klitzke
I was browsing the documentation for GLib, and came across this:
http://library.gnome.org/devel/glib/stable/glib-Type-Conversion-Macros.html#GINT-TO-POINTER--CAPS
I was interested in the caveat that storing a pointer in an integer is
not portable. I'm not much of a C/C++ hacker so I was wondering: why
is this not portable? The best guess that I could come up with is that
on some architectures the size of a pointer might be larger than the
size of an int, e.g. on x86-64 Linux builds (with gcc/glibc anyhow) I
think pointers are 8 bytes and ints are 4 bytes. Is this the only
reason? Does the C standard guarantee the reverse -- that a pointer is
always at least as large as an int?
Inquiring minds want to know.
http://library.gnome.org/devel/glib/stable/glib-Type-Conversion-Macros.html#GINT-TO-POINTER--CAPS
I was interested in the caveat that storing a pointer in an integer is
not portable. I'm not much of a C/C++ hacker so I was wondering: why
is this not portable? The best guess that I could come up with is that
on some architectures the size of a pointer might be larger than the
size of an int, e.g. on x86-64 Linux builds (with gcc/glibc anyhow) I
think pointers are 8 bytes and ints are 4 bytes. Is this the only
reason? Does the C standard guarantee the reverse -- that a pointer is
always at least as large as an int?
Inquiring minds want to know.