Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

size of size_t compared to unsigned int

Tags:

c++

c

Does anyone know any toolchain/platform/target combination where the maximum value of size_t is smaller than the maximum value of unsigned int?

I think both the C and C++ standards allow this in principle and it might (in theory) be useful on some wierd MCUs, but I've never seen this in practice.

Note:
I deliberately tagged this with both c and c++, as I'm interested in answers for both languages (if your answer is language specific, please say so) and I haven't yet seen any toolchain/target combination that uses different sizes for those types in c and c++ anyway.

like image 553
MikeMB Avatar asked Jun 18 '18 09:06

MikeMB


1 Answers

H8/300 can be configured to. With GCC (configured with triple h8300-elf or h8300-rtems), this is the -mint32 flag:

gcc/config/h8300/h8300.h:555:
#define SIZE_TYPE                               \
  (TARGET_H8300 || TARGET_NORMAL_MODE ? TARGET_INT32 ? "short unsigned int" : "unsigned int" : "long unsigned int")

So when -mint32 is passed making 32-bit int, size_t is based on 16-bit short.

(Also note that, per comments in that file, GCC requires that size_t and void * must be the same size)

like image 188
o11c Avatar answered Sep 19 '22 08:09

o11c