実行環境
OS Darwin Kernel Version 18.7.0
CPU intel i5-8500
コンパイラ gcc (中身はclangみたいです)
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *buf = malloc(UINT_MAX);
size_t i = INT_MAX;
int n = write(1, buf, ++i);
printf("%p\n%d\n%s\narg : %zu\nmax : %zd\n", buf, n, strerror(errno), i, SSIZE_MAX);
}
出力結果
0x101d22000
-1
Invalid argument
arg : 2147483648
max : 9223372036854775807
man 2 write
で表示したマニュアルには以下の様に書いてありましたが、SSIZE_MAXはINT_MAXより大きいようでした
If the value of nbyte is greater than {SSIZE_MAX}, the result is implementation-defined.
どうして正常に出力されないのでしょうか?
同様のコードでもubuntuでは正常に出力されました
処理系定義なのでしょうか?