this simple code snippet
char a[] ="1";
char *end;
double val;
val = strtod(a, &end);
printf("%f %d\n", val, atoi(a));
prints out
6217.000000 1
does strtod not work or am I doing something wrong?
On 4/16/21 11:20 PM, vavr...@gmail.com wrote:
this simple code snippet
char a[] ="1";
char *end;
double val;
val = strtod(a, &end);
printf("%f %d\n", val, atoi(a));
prints out
6217.000000 1
does strtod not work or am I doing something wrong?Sitting at my Linux box, this code works as expected:
#include <stdio.h>
#include <stdlib.h>
void main()
{
char a[] ="1";
char *end;
double val;
val = strtod(a, &end);
printf("%f %d\n", val, atoi(a));
}
But I find if I omit <stdlib.h> output get a little wonky (and I have attendant compiler warnings). Are you including that?
Use #pragma lint 7 (or -1) to catch missing functions and prototypes.
On Saturday, April 17, 2021 at 6:20:10 PM UTC-7, Kelvin Sherlock wrote:dereference the result.
Use #pragma lint 7 (or -1) to catch missing functions and prototypes.I didn't really appreciate the value of function prototypes in C until I was trying to call malloc() on a IIgs. Without the prototype it assumed the function returned a 16-bit int instead of a 32-bit pointer, and things didn't go well when I tried to
Since "double" is wider than 16 bits, every function that uses it as an argument or result needs a prototype. Turning up the warnings is a very good idea.
[...] The following even does not work correct
int x=1;
double d =x;
d winds up being some large number. Does anyone need to know if you need to startup SANE to use doubles?
I usually have lint -1 for compiles. I was running into the issue in a larger >project where I did have lint -1 so I wrote quick little test program to >test it out where I forgot the lint. While the little test program works
the large project does not. The following even does not work correct
int x=1;
double d =x;
d winds up being some large number. Does anyone need to know if you need
to startup SANE to use doubles?
On Sunday, April 18, 2021 at 10:55:18 AM UTC-4, thef...@gmail.com wrote:
On Saturday, April 17, 2021 at 6:20:10 PM UTC-7, Kelvin Sherlock wrote:I was trying to call malloc() on a IIgs. Without the prototype it assumed
Use #pragma lint 7 (or -1) to catch missing functions and prototypes.I didn't really appreciate the value of function prototypes in C until
the function returned a 16-bit int instead of a 32-bit pointer, and things >didn't go well when I tried to dereference the result.
Since "double" is wider than 16 bits, every function that uses it as an >argument or result needs a prototype. Turning up the warnings is a very good >idea.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (3 / 13) |
Uptime: | 69:59:29 |
Calls: | 6,656 |
Calls today: | 2 |
Files: | 12,200 |
Messages: | 5,332,146 |
Posted today: | 1 |