mwm@ucbopal.berkeley.edu (Mike (I'll be mellow when I'm dead) Meyer) (05/13/86)
In article <8605102156.AA03379@cory> dillon@CORY.BERKELEY.EDU (Matt Dillon) 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(); *BLUSH* And here I've been assuming that the cast told the compiler that this function returned something long, so that those with a different view of the world would understand. Well, time to start fixing my code when I fix it :-). BTW, Matt, that should be: extern struct Window *OpenWindow(struct NewWindow *); win = OpenWindow(New_Window); Of course, if you're using a deficient compiler (like the one on 4BSD), it won't understand the ANSI argument declaration :-). Now, for a suggestion: When you build the include file for a set of functions, PUT THE FUNCTION DECLARATIONS IN THE HEADER FILE!! Witness the ndir.c/dir.h pair I mailed to info-amiga a couple of days ago. This means that 1) everybody who uses those functions won't have to write the delcaration; 2) you won't get into problems with compilers that correctly make int's 16 bits on the 68000; 3) if you use the ANSI argument declaration feature (and you should, for the same reasons you should declare the function in the first place!), you get benefit #2 on the arguments as well as the return value. Maybe if C/A does this for the include files for 1.2 (declare the functions in the header that declares the type of the return value), maybe the next release of the Lattice compiler will have it for us. BTW, if anyone's still listening: how's us normal, everyday hackers (who aren't developers) going to get the new include files for 1.2? Thanx, <mike