¡No incluir stdlib.h no produce ningún error de compilación!
Esperemos que esta sea una pregunta muy simple. El siguiente es el C pgm (test.c) que tengo.
#include <stdio.h>
//#include <stdlib.h>
int main (int argc, char *argv[]) {
int intValue = atoi("1");
double doubleValue = atof("2");
fprintf(stdout,"The intValue is %d and the doubleValue is %g\n", intValue, doubleValue);
return 0;
}
Tenga en cuenta que estoy usando atoi () y atof () de stdlib.h, pero no incluyo ese archivo de encabezado. ¡Compilo el pgm (gcc test.c) y no obtengo ningún error del compilador!
Ejecuto el pgm (./a.out) y aquí está la salida, que está mal.
The intValue is 1 and the doubleValue is 0
Ahora incluyo stdlib.h (eliminando los comentarios antes del #include) y lo vuelvo a compilar y ejecutar. Esta vez obtengo el resultado correcto:
The intValue is 1 and the doubleValue is 2
¿Cómo es que el compilador no se quejó de no incluir stdlib.h y todavía me dejó usar las funciones atoi (), atof ()?
Mi información de gcc:
$ gcc --version
gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27)
Cualquier pensamiento apreciado!