jeff@cpoint.UUCP (Jeffrey J. Griglack) (12/15/88)
I received my copy of Lattice C 5.0 yesterday and immediatly tried it on some code I had written and compiled under 4.0. I got an ERROR for a call to a function that did was not made in the form of the function prototype. To correct this I had to cast the perameter to a byte pointer (instead of a pointer of a type I had defined myself). My problem is that I believe I should have just gotten a WARNING instead of a hard error. Does the new ANSI standard say that this should produce a warning or is it just something peculiar to the Lattice implementation? I would think that it would sometimes be nice to say, "Yes, I know I called it wrong. I meant to." C was not supposed to be an idiot-proofed (read "restrictive") language. This is my first posting, so I can only assume the address above is correct. I would think that any replies would be of general interest anyway. Please refrain from flaming. This is, I think, a legitimate question and I would appreciate thoughtful answers. Jeff Griglack ************************** * This space for rent. * **************************
jyegiguere@lotus.waterloo.edu (Eric Giguere) (12/18/88)
In article <1427@cpoint.UUCP> jeff@cpoint.UUCP (Jeffrey J. Griglack) writes: >I received my copy of Lattice C 5.0 yesterday and immediatly tried >it on some code I had written and compiled under 4.0. I got an >ERROR for a call to a function that did was not made in the form >of the function prototype. To correct this I had to cast the >perameter to a byte pointer (instead of a pointer of a type I had >defined myself). > >My problem is that I believe I should have just >gotten a WARNING instead of a hard error. Does the new ANSI >standard say that this should produce a warning or is it just >something peculiar to the Lattice implementation? I would think >that it would sometimes be nice to say, "Yes, I know I called it >wrong. I meant to." C was not supposed to be an idiot-proofed >(read "restrictive") language. I don't have the Standard in front of me, so I can't quote it, but the Standard says that if a function prototype is in scope, all parameters in a call to that function should be converted to agree with what the prototype declares. So if you say extern void foo( float ); foo( 1.0 ); it should implicitly convert the 1.0 (type double) to float. To me this implies that the compiler should not generate an error message. A warning makes more sense because it might catch any inadvertent conversions --- being able to turn the warning off would also be desirable. I don't have Lattice 5.0, so I can't comment on this, but I do hope that they've updated their function library to make the functions invariant to the default promotion vs. prototype conversion differences. In other words, the function putc should be defined as: int putc( int c, FILE *stream ) { /* etc */ } so that it works properly whether the full prototype is in scope or not. Otherwise if the first parm was defined as a char, the following code would be a problem: #ifdef PROTOTYPES extern int putc( char, STREAM * ); #endif void foo1( char c ) { putc( c, stdout ); } If PROTOTYPES is defined, the first parm will be passed to putc as a char. Otherwise, the default promotions will be used an c will be promoted to an int first..... This is something to watch out in your own code, too, especially if you are writing something to be portable between Lattice (prototypes) and Manx (no prototypes). -- --------------------------------------------------------------------------- Eric Giguere 268 Phillip St. #CL-46, Waterloo, Ont. N2L 6G9 jyegiguere@lotus.waterloo.edu (519) 746-0792 GIGUERE@WATCSG.BITNET "No, that's not how you pronounce it..."
fgd3@jc3b21.UUCP (Fabbian G. Dufoe) (12/18/88)
From article <1427@cpoint.UUCP>, by jeff@cpoint.UUCP (Jeffrey J. Griglack): > Comments about Lattice C 5.0 and error generated by function prototype > mismatch deleted. I don't know about the ANSI standard but the way Lattice 4.02 worked (and I think version 5.0 works the same way) you get an error if you've specified a prototype for a function and then not complied with it. But if you don't use the prototyping feature you won't get the errors. The main difference I've noticed is 5.0 has a lot more prototypes built for functions supplied by Lattice. In particular, I ran afoul of their definition of main() as a void in stdlib.h. I'm used to declaring main() an int so I can return an error code. --Fabbian Dufoe 350 Ling-A-Mor Terrace South St. Petersburg, Florida 33705 813-823-2350 UUCP: ...codas!usfvax2!jc3b21!fgd3 ...uunet!pdn!jc3b21!fgd3
dillon@POSTGRES.BERKELEY.EDU (Matt Dillon) (12/20/88)
You can't return an error code from main() via return. The only way to return an error code is with exit() or _exit(). returning from main() always generates an error code of 0. This is why main() might be declared void. Why? Lots of people let main() fall through to exit a program, which means the 'return value' would otherwise be garbage. -Matt : I don't know about the ANSI standard but the way Lattice 4.02 worked :(and I think version 5.0 works the same way) you get an error if you've :specified a prototype for a function and then not complied with it. But if :you don't use the prototyping feature you won't get the errors. The main :difference I've noticed is 5.0 has a lot more prototypes built for :functions supplied by Lattice. In particular, I ran afoul of their :definition of main() as a void in stdlib.h. I'm used to declaring main() :an int so I can return an error code. : :--Fabbian Dufoe : 350 Ling-A-Mor Terrace South : St. Petersburg, Florida 33705 : 813-823-2350 : :UUCP: ...codas!usfvax2!jc3b21!fgd3 : ...uunet!pdn!jc3b21!fgd3
fgd3@jc3b21.UUCP (Fabbian G. Dufoe) (12/21/88)
From article <8812192102.AA25347@postgres.Berkeley.EDU>, by dillon@POSTGRES.BERKELEY.EDU (Matt Dillon): > > You can't return an error code from main() via return. The only > way to return an error code is with exit() or _exit(). returning from main() > always generates an error code of 0. This is why main() might be declared > void. Why? Lots of people let main() fall through to exit a program, which > means the 'return value' would otherwise be garbage. Well, I used to write programs like this: main() { if (error) exit(error_code); return(0); } because main defaults to an int if you don't declare it differently and Lattice complained if I let it drop through without a return statement. It took me a little while to figure out why I couldn't do it under version 5.0. Then I changed my style to this: void main() { if (error) exit(error_code); exit(0); } It was really no problem to make the change and I'm pleased to have the compiler tighten up on questionable practices. Version 4 also defined main() as a void function in stdlib.h, but the compiler didn't care if I did it differently. --Fabbian Dufoe 350 Ling-A-Mor Terrace South St. Petersburg, Florida 33705 813-823-2350 UUCP: ...codas!usfvax2!jc3b21!fgd3 ...uunet!pdn!jc3b21!fgd3