我的strtol函數在溢出轉換期間未能設置errno。Strtol在溢出轉換時未設置errno
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <getopt.h>
#include <errno.h>
#include <stdlib.h>
int main(int argc, char **argv) {
errno = 0;
int e = strtol("1000000000000000", NULL, 10);
printf("%d %d\n", errno, e);
return 0;
}
回報
0 -1530494976
我該怎麼辦錯了嗎?
編譯
gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
選項
gcc -Wall -std=gnu99 -O2
你使用什麼編譯器(及其版本)?你有沒有包含所有必要的標題? –
手冊頁說什麼是'strol'的返回類型? – kaylum
好吧,編譯器和頭文件增加 – Krzysztofik