Is size_t always unsigned int

Are there any implementations that are size_tdefined as something else than unsigned int? I worked on every system, it was defined as unsigned int, so I'm just curious.

+4
source share
7 answers

x86-64 and aarch64 (arm64) Linux, OS X and iOS have size_t, which are ultimately defined as unsigned long. (This is the LP64 model, which is part of the ABI platform, which also defines functions such as calling function calls, etc. Other architectures may vary.) Even the 32-bit x86 and ARM architectures use unsigned longfor these OSs, although longit turns out to be the same representation, as intin these cases.

I am sure it will be unsigned __int64/ unsigned long longon Win64. (which uses the LLP64 model)

+5
source

No. But this is an unsigned integer type. It does not have to be int.

For C ++

http://en.cppreference.com/w/cpp/types/size_t

Standard C ++ Section 18.2.6

size_t - , , .

linux; " ++ size_t, linux" long unsigned int

C

( C, ++.)

:

sizeof (size_t) 32- 64- ?

+4

, ( unsigned int). CPPReference:

std:: size_t - sizeof

, , , , .

+2

, size_t "" . , , unsigned int, ., , (unsigned long) , , 64- GNU/Linux.

N4296, 18.2.6:

size_t - , , , .

, N897 () 6.5.3.4...

sizeof, , , ( header <stddef.h>) size_t, . size_t . , , size_t , sizeof , , , size_t, , , unsigned long C89 uintmax_t C9X. , a of N,

N == sizeof(a)/sizeof(a[0])

, size_t .

+2

sys/types.h man page:

size_t .

, short, int, long long long.

+1

. size_t unsigned int.

C, 6.5.3.4:

, ( ) size_t, <stddef.h> ( ).

C size_t undefined.

Open Group (POSIX ..):

64-

...

sizeof (char) <= sizeof (short) <= sizeof (int) <= sizeof (long) = SizeOf (size_t)

:

size_t size_t. , , .

+1

. cpp.sh, gcc:

#include <iostream>

int main()
{
  std::cout << sizeof(unsigned int) << " " << sizeof(unsigned long) << " " << sizeof(size_t) << "\n";
}

:

4 8 8

0

Source: https://habr.com/ru/post/1614869/


All Articles