[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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" <debian@aokiconsulting.com>
To: <debian-user@lists.debian.org>
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 <stdio.h>
> /*# include <stdlib.h>*/ /*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.0000
> $
> ----------------
> 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 <debian@aokiconsulting.com>, GnuPG-key: 1024D/D5DE453D  +
> +  For my debian quick-reference, peek into:                          +
> +                               http://www.aokiconsulting.com/quick/  +
>
>
> --
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact
listmaster@lists.debian.org
>
>



Reply to: