A
A. Farber
Hello,
I have this simple program:
#include <stdio.h>
#include <stdlib.h>
int main() {
char *args = "2162508224";
printf("args=%s, atoi=%lu, atol=%lu\n",
args, atoi(args), atol(args));
}
which prints (tested on OpenBSD and RHE Linux):
args=2162508224, atoi=2147483647, atol=2147483647
I understand that the "wrong" 2147483647 value is the
#define INT_MAX 0x7fffffff
from the /usr/include/sys/limits.h. But why is the last value wrong
too? I was expecting the atoi() to fail, but atol() to work fine...
Thank you
Alex
I have this simple program:
#include <stdio.h>
#include <stdlib.h>
int main() {
char *args = "2162508224";
printf("args=%s, atoi=%lu, atol=%lu\n",
args, atoi(args), atol(args));
}
which prints (tested on OpenBSD and RHE Linux):
args=2162508224, atoi=2147483647, atol=2147483647
I understand that the "wrong" 2147483647 value is the
#define INT_MAX 0x7fffffff
from the /usr/include/sys/limits.h. But why is the last value wrong
too? I was expecting the atoi() to fail, but atol() to work fine...
Thank you
Alex