Problema con programa en C. Siguiendo un tutorial para generar una librería propia generé un archivo header po.h y un compreso libpo.a
Sucede que gcc logra linkear mi librería, pero.. el código NO funciona como debería.
teóricamente debe devolver un double (base*base*base), sin embargo devuelve números aleatorios y extraños.
Ejemplo de output:
Citar
[po6x@localhost my_first_library]$ ./my_first_test Cube of 3 is: -2032509192
[po6x@localhost my_first_library]$ ./my_first_test Cube of 3 is: -1976814360
[po6x@localhost my_first_library]$ ./my_first_test Cube of 3 is: -1625557320
Comando de creación de la librería y del programa anterior
Citar
Lib generated with>
[po6x@localhost my_first_library]$ar rs libpo.a cub.o fact.o
Compilation>
[po6x@localhost my_first_library]$ gcc -o my_first_test my_first_test.c -lpo
No sé si sea un overflow o qué sucede. Alguna pista?
El código que retorna la salida errónea con números aleatorios (raros):
#include <stdio.h>
#include <po.h>
//Name:my_first_test
int main(int argc,char *argv[]){
double base=3;
printf("Cube of %d is: %d \n",base,cubo(base) );
return (0);
}
Content of headers file po.h
//Archivo de cabeceras para libreria propia
extern int fact(int);
extern double cubo(double);
The function itself Content of cub.c:
double cubo(double base){
return (base*base*base);
}