Re: howto identify missing stdlib.h after compile?
On Wed, Apr 25, 2001 at 09:50:22PM +1000, Kevin Easton wrote: > Of course, if you don't include the declaration of atof (which is what's in > stdlib.h), then the compiler can't check the type and number of parameters, > and the type of the return value of the function. When I was checking return type by gdb using correctly compiled one, it returns int on whatis atof(). Even more confusing, set x=atoi("123.456") does not work in correct program/gdb and return same result as incorrect program. Is this gdb thing??? Osamu -- ~\^o^/~~~ ~\^.^/~~~ ~\^*^/~~~ ~\^_^/~~~ ~\^+^/~~~ ~\^:^/~~~ ~\^v^/~~~ + Osamu Aoki <[EMAIL PROTECTED]>, GnuPG-key: 1024D/D5DE453D + + My debian quick-reference, http://www.aokiconsulting.com/quick/+
RE: howto identify missing stdlib.h after compile?
> > Unless I compile with -Wall, following code compiles with no warning > with "gcc -g -o example example.c". > > How should I tell that this code is broke after compile? > -- > # include > /*# include */ /*Not to have this for atof is the bug*/ > int main(int argc, char **argv) { > float x=0; > x=atof("123.456"); > printf("%8.4f\n",x); > return 0; > } > > $ ./example > 1078984704. > $ > If you can't use -Wall you might try lint. There is a lint package called "lclint". "lint noproto.c" (your example code) produces this: LCLint 2.4b --- 18 Apr 98 noproto.c: (in function main) noproto.c:5:1: Assignment of double to float: x = atof("123.456") Types are incompatible. (-type will suppress message) noproto.c:3:14: Parameter argc not used A function parameter is not used in the body of the function. If the argument is needed for type compatibility or future plans, use /[EMAIL PROTECTED]@*/ in the argument declaration. (-paramuse will suppress message) noproto.c:3:27: Parameter argv not used Finished LCLint checking --- 3 code errors found hth jim
Re: howto identify missing stdlib.h after compile?
Hi, You can't, because it's not. As long as your program is linked with a library that exports atof (in this case, glibc), and you call it correctly, then there's no problem. Of course, if you don't include the declaration of atof (which is what's in stdlib.h), then the compiler can't check the type and number of parameters, and the type of the return value of the function. That's obviously bad - which is why you should always compile with -Wall. It'll then warn you that you're using a function it knows nothing about. - Kevin. - Original Message - From: "Osamu Aoki" <[EMAIL PROTECTED]> To: Sent: Wednesday, April 25, 2001 6:59 PM Subject: howto identify missing stdlib.h after compile? > Unless I compile with -Wall, following code compiles with no warning > with "gcc -g -o example example.c". > > How should I tell that this code is broke after compile? > -- > # include > /*# include */ /*Not to have this for atof is the bug*/ > int main(int argc, char **argv) { > float x=0; > x=atof("123.456"); > printf("%8.4f\n",x); > return 0; > } > > $ ./example > 1078984704. > $ > > FYI: > "nm example" produces: (Same with or without bug.) > ... > 080482bc ? _init > 08048350 T _start > U atof@@GLIBC_2.0 > 080494c8 d completed.4 > ... > > The only difference with correct program is: > @@ -1,5 +1,5 @@ > 08048374 t Letext > -08048452 t Letext > +08048457 t Letext > 08049504 ? _DYNAMIC > 080494e0 ? _GLOBAL_OFFSET_TABLE_ > 080484ac R _IO_stdin_used > > I can not tell from this that this program is broke. gdb print same as > printf. > -- > ~\^o^/~~~ ~\^.^/~~~ ~\^*^/~~~ ~\^_^/~~~ ~\^+^/~~~ ~\^:^/~~~ ~\^v^/~~~ > + Osamu Aoki <[EMAIL PROTECTED]>, GnuPG-key: 1024D/D5DE453D + > + For my debian quick-reference, peek into: + > + http://www.aokiconsulting.com/quick/ + > > > -- > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] > >
howto identify missing stdlib.h after compile?
Unless I compile with -Wall, following code compiles with no warning with "gcc -g -o example example.c". How should I tell that this code is broke after compile? -- # include /*# include */ /*Not to have this for atof is the bug*/ int main(int argc, char **argv) { float x=0; x=atof("123.456"); printf("%8.4f\n",x); return 0; } $ ./example 1078984704. $ FYI: "nm example" produces: (Same with or without bug.) ... 080482bc ? _init 08048350 T _start U atof@@GLIBC_2.0 080494c8 d completed.4 ... The only difference with correct program is: @@ -1,5 +1,5 @@ 08048374 t Letext -08048452 t Letext +08048457 t Letext 08049504 ? _DYNAMIC 080494e0 ? _GLOBAL_OFFSET_TABLE_ 080484ac R _IO_stdin_used I can not tell from this that this program is broke. gdb print same as printf. -- ~\^o^/~~~ ~\^.^/~~~ ~\^*^/~~~ ~\^_^/~~~ ~\^+^/~~~ ~\^:^/~~~ ~\^v^/~~~ + Osamu Aoki <[EMAIL PROTECTED]>, GnuPG-key: 1024D/D5DE453D + + For my debian quick-reference, peek into: + + http://www.aokiconsulting.com/quick/ +