Question about using void *

Warner Losh imp at Solbourne.COM
Sat Jan 19 09:53:08 AEST 1991


Given something like the following:

struct foo {
	void *bar;
};

struct foo fred[] = {
	{ (void *) 1},
	{ (void *) 3}
};

struct foo george[] = {
	{ (void *) "Warner"},
	{ (void *) "Losh"}
};

In the program where I see this being done, there is a tag that tells
what type each element of the struct foo is, plus some other
information.  What I've presented here are just the basics.

My question is: Is this portable?  Can I stuff an integer into a
pointer and expect to get it back out again?  I know that there are
problems with going the other way (stuff a pointer into an int and
then try to get it back out).

I couldn't find anything in my K&R II to tell me how kosher this
method is.

Warner
-- 
Warner Losh		imp at Solbourne.COM
We sing about Beauty and we sing about Truth at $10,000 a show.



More information about the Comp.lang.c mailing list