3 ms·
One of my friends likes to scold me about using a programming language (Python) that doesn't enforce type declarations. I gently remind him that his language (C
by analog31 4y ago
One of my friends likes to scold me about using a programming language (Python) that doesn't enforce type declarations. I gently remind him that his language (C) has eight different types of integers.
- einpoklum 4y ago{ char, short, int, long, long long } x { signed, unsigned } = 10 types, and then there's bool and maybe int128_t, so maybe 12.
- analog31 4y agoAha, I had forgotten about char.
- Aardwolf 4y agoHeh, it has way more than 8. For char, you have 3: signed char, unsigned char and char. It's not specified if char without keyword is signed or unsigned. You have integer types such as size_t, ssize_t and ptrdiff_t. They may, under the hood, match one of the other standard int types, however this differs per platform, so you can't e.g. just easily print size_t using the standard printf formatters, you really have to treat is as its own type. Also wchar_t and such of course. Then you have all the integers in stdint.h and inttypes.h. Same here applies as for size_t. At least you know how many bits you get from several of them, unlike from something like "long". Then your compiler may also provide additional types such as __int128 and __uint128_t.
- spc476 4y ago> so you can't e.g. just easily print size_t using the standard printf formatters This has been fixed in C99. For size_t, it's "%zu", for ptrdiff_t it's "%td", for ssize_t it's "&zd" and for wchar_t, it's "&lc".