LoginSignup
4
1

More than 5 years have passed since last update.

size_tの最大値

Last updated at Posted at 2019-02-10

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

4
1
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1