J
jan olieslagers
Given following code, how to understand the resulting output?
The integer version works, but a straightforward eqivalent for floats or
double produces gibberish (or what must I call the "nan"?)
Seems like the non-integer parameters never get entered into the
functions, what am i missing?
NB this is with gcc 4.2.1 on SuSe 10.3 Linux.
Thanks in advance, and sincere apologies if I _still_ haven't done
enough RTFM!
<code>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int test_function(input_int)
int input_int;
{
printf(" C1: %d \n",input_int);
return (input_int -2);
}
int test_float(input_float)
float input_float;
{
printf(" C2: %f \n",input_float);
return (input_float -2);
}
int test_double(input_double)
double input_double;
{
printf(" C3: %f \n",input_double);
return (input_double -2);
}
main (){
printf("%d %d\n",3,test_function(3));
printf("%d %d\n",5,test_function(5));
printf("%f %f\n",3,test_float(3));
printf("%f %f\n",5,test_float(5));
printf("%f %f\n",3,test_double(3));
printf("%f %f\n",5,test_double(5));
}
</code>
<output>
C1: 3
3 1
C1: 5
5 3
C2: -1.998314
nan 2.399940
C2: -1.998314
nan 2.399940
C3: -1.998314
nan 2.399940
C3: -1.998314
nan 2.399940
</output>
The integer version works, but a straightforward eqivalent for floats or
double produces gibberish (or what must I call the "nan"?)
Seems like the non-integer parameters never get entered into the
functions, what am i missing?
NB this is with gcc 4.2.1 on SuSe 10.3 Linux.
Thanks in advance, and sincere apologies if I _still_ haven't done
enough RTFM!
<code>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int test_function(input_int)
int input_int;
{
printf(" C1: %d \n",input_int);
return (input_int -2);
}
int test_float(input_float)
float input_float;
{
printf(" C2: %f \n",input_float);
return (input_float -2);
}
int test_double(input_double)
double input_double;
{
printf(" C3: %f \n",input_double);
return (input_double -2);
}
main (){
printf("%d %d\n",3,test_function(3));
printf("%d %d\n",5,test_function(5));
printf("%f %f\n",3,test_float(3));
printf("%f %f\n",5,test_float(5));
printf("%f %f\n",3,test_double(3));
printf("%f %f\n",5,test_double(5));
}
</code>
<output>
C1: 3
3 1
C1: 5
5 3
C2: -1.998314
nan 2.399940
C2: -1.998314
nan 2.399940
C3: -1.998314
nan 2.399940
C3: -1.998314
nan 2.399940
</output>