Edited at

size_tの最大値


iconv()のman

manでiconv()のエラー判定みてたら


RETURN VALUE

The iconv() function returns the number of characters converted in a nonreversible way during this call;

reversible conversions are not counted. In case of error, it sets errno and returns (size_t) -1.


(size_t) -1ってなんなの?


(size_t) -1

サンプル書いて

#include <stdio.h>

int main(void)
{
printf("size_t %zu\n", (size_t)-1);
printf("unsigned int %zu\n", (unsigned int)-1);
return 0;
}

動かしてみる

$ gcc -m32 test1.c ; ./a.out

size_t 4294967295
unsigned int 4294967295

$ gcc test1.c ; ./a.out
size_t 18446744073709551615
unsigned int 4294967295

なるほどね。

https://stackoverflow.com/questions/1420982/invalid-value-for-size-t