Pointer Problems

Ray Spalding cc100aa at prism.gatech.EDU
Thu Aug 16 01:27:14 AEST 1990


In article <8aliOrS00WBMI1UVYX at andrew.cmu.edu> gh1r+ at andrew.cmu.edu (Gaurang Hirpara) writes:
>Ok. I have a struct, call it idiot, with some elements in it, nothing unusual.
>
>Now, I have another struct, which contains in it a generic 
>pointer (i.e. Ptr <pointername>). 
>How can I make <pointername> point to idiot, AND be able to access the 
>resulting pointer as a pointer to struct. My main problem is that even
>if I do manage to get them to point to the same place (which is a problem
>all by itself), I can't access the internal members of the struct. 

You should be able to use a cast, e.g:
	x = ((struct idiot *)pointername)->element;

Note that "Ptr" is not part of the C language; it's probably typedef'd
somewhere to "void *" or, to accommodate older implementations, "char *".

-- 
Ray Spalding, Technical Services, Office of Information Technology
Georgia Institute of Technology, Atlanta Georgia, 30332-0275
uucp:     ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!cc100aa
Internet: cc100aa at prism.gatech.edu



More information about the Comp.lang.c mailing list