News for hackers. Stuff that matters.
Re:Porting to GCC 14: C language issues by _kst_ on Monday February 19, 2024 @11:23AM (#39431525)
I think there are two reasons int has not gone from 32 to 64 bits on 64-bit systems.

Part of it is backward compatibility: code written to assume 32-bit int could break. (Arguably such code is badly written, but breaking it would still be inconvenient.)

Another part is that C has a limited number of predefined integer types; char, short, int, long, long long (plus unsigned variants and signed char). If char is 8 bits and int is 64 bits, then you can't have both a 16-bit and a 32-bit integer type. Extended integer types (introduced in C99) could address this, but I don't know of any compilers that provide them.

Re:Porting to GCC 14: C language issues by myrmidon on Monday February 19, 2024 @11:37AM (#39431732)
> Extended integer types (introduced in C99) could address this, but I don't know of any compilers that provide them.

What environment are you working in? Because I don't know a single half-recent compiler that does not provide stdint (uint8_t, ..., int64_t), but I mostly work with GCC/LLVM toolchains.

Re:Porting to GCC 14: C language issues by dzaima on Monday February 19, 2024 @12:16PM (#39432196)
Extended integer types aren't necessarily related to stdint.h - in the vast majority if not every one of those "half-decent compilers" the stdint.h types are just typedefs over plain old char/short/int/long/long long, which are not extended integer types. Extended integer types is a mechanism to allow having types other than those.
Re:Porting to GCC 14: C language issues by myrmidon on Monday February 19, 2024 @01:12PM (#39432848)
> in the vast majority if not every one of those "half-decent compilers" the stdint.h types are just typedefs over plain old char/short/int/long/long long, which are not extended integer types.

Sure, but isn't that just an implementation detail? Because I really don't care if my int64_t is internally typedef'd to "long long int" or "__m64", as long as there is a standardized interface to ask for it.

Re:Porting to GCC 14: C language issues by dzaima on Monday February 19, 2024 @01:19PM (#39432936)
Point being, _kst_'s comment of "I don't know of any compilers that provide them" is correct - there are few if any compilers that actually have actual extended integer types, and thus introducing such in compilers might be non-trivial, and plenty of code may exist under the assumption that they don't exist and thus could break (things like integer promotion rules, _Generic, varargs; and also intmax_t is of mention as it must be at least as wide as any supported standard or extended integer type (which is also why clang/gcc __int128 doesn't qualify as an integer type as per the standard))
Re:Porting to GCC 14: C language issues by retrac on Monday February 19, 2024 @11:54AM (#39431942)
Some embedded compilers will provide stdint. And if the compiler doesn't, I've found that one of the first headers written for a project ends up being an equivalent to stdint.

It's pretty common to develop part of an embedded C program under Linux or similar host environment. Better debuggers, better profiling tools, etc. And uint8_t and friends are particularly important when you're working cross-platform.

Re:Porting to GCC 14: C language issues by bewaretheirs on Monday February 19, 2024 @11:37AM (#39431737)
If you can have "long long", why not "short short"?

In that alternate universe, char could be 8 bits, short short 16, short 32, and int 64.

Re:Porting to GCC 14: C language issues by cpeterso on Monday February 19, 2024 @03:08PM (#39434145)
And “long short” and “short long” types. :)
Re:Porting to GCC 14: C language issues by travisgriggs on Tuesday February 20, 2024 @12:19AM (#39438301)
For 24 bits?
Re:Porting to GCC 14: C language issues by stkdump on Monday February 19, 2024 @12:43PM (#39432492)
Since the extended integer types are just aliases to the other types, they wouldn't solve the problem. Also in C++ these aliases create a problem with overload sets when you mix the two worlds and try to produce portable code. For example long on some platforms is 32 bit and 64 bit on others, also platforms use inconsistent fundamental types for 32 and 64 bit aliases. All in all if you want to produce portable code you neither use those extended integer types nor long. You assume char, short, int, long long are 8, 16, 32, 64 bit respectively, which holds on all relevant platforms.
Re:Porting to GCC 14: C language issues by dzaima on Monday February 19, 2024 @01:12PM (#39432854)
Extended integer types are decidedly not just aliases to other types - the C standard has separate "standard integer types" which are the regular char/short/int/long/long long, and "extended integer types" which are any additional implementation-specific types. stdint.h-defined types can be either of those categories (and on regular clang/gcc they're all standard integer types and not extended ones). So you could have a system with char/short/int/long/long long being 8/16/64/64/64-bit respectively and still be able to provide an int32_t that's none of those; just, noone does.
Re:Porting to GCC 14: C language issues by dataflow on Monday February 19, 2024 @02:37PM (#39433750)
What really sucks about this in C++ is that it prevents you from knowing whether you can overload based on those types.