dillon@CORY.BERKELEY.EDU (Matt Dillon) (05/11/86)
The most common problem is really not the compiler's fault. Many of you all assume integers are the same size as pointers, and do things like: win = (struct Window *)OpenWindow() ... This is incorrect. If the compiler uses 16-bit integers, and since OpenWindow() returns an integer, you will loose the MSB word of the returned value when it is converted to a pointer. The proper way to do the call is: extern struct Window *OpenWindow(); win = OpenWindow(); If the library or system call can return different types of pointers, then you should still extern it to SOME type of pointer: extern char *OpenLibrary(); struct GfxBase GfxBase; struct MathBase MathBase; GfxBase = (struct GfxBase *)OpenLibrary( ...) MathBase= (struct MathBase *)OpenLibrary( ...) If you will never use the returned pointer (but still must set it for the library routines to use), then it would suffice to just declare everything as char *: extern char *OpenLibrary(); char *GfxBase, *MathBase; GfxBase = OpenLibrary( ...) MathBase= OpenLibrary( ...) -Matt
higgin@cbmvax.cbm.UUCP (Paul Higginbottom) (05/12/86)
In article <8605102156.AA03379@cory> dillon@CORY.BERKELEY.EDU.UUCP writes: > > The most common problem is really not the compiler's fault. Many >of you all assume integers are the same size as pointers, and do things like: > > win = (struct Window *)OpenWindow() ... > > This is incorrect. If the compiler uses 16-bit integers, and since >OpenWindow() returns an integer, you will loose the MSB word of the >returned value when it is converted to a pointer. The proper way to do >the call is: > > extern struct Window *OpenWindow(); > > win = OpenWindow(); >.... <line eater> Sounds like there's an echo in this net (net, net, net...) Paul D Higginbottom (on cbmvax)