News for hackers. Stuff that matters.
Re:Problems of C, and how Zig addresses them by pavlov on Monday July 03, 2023 @12:33PM (#36575329)
The C standard effectively can’t add new types without the “_t” suffix, so they’re stuck with limitations that a brand new language won’t have.
Re:Problems of C, and how Zig addresses them by pitaj on Monday July 03, 2023 @01:36PM (#36576338)
Can't they add a new header file?
Re:Problems of C, and how Zig addresses them by flohofwoe on Monday July 03, 2023 @01:47PM (#36576425)
What if a library API needs to include this new header because it wants to use the new typedefs in its API declarations but your own code (which needs to include the library header) also has its own 'u8' typedefs?

(PS: it's probably ok because C compilers seem to accept redundant typedefs)

Re:Problems of C, and how Zig addresses them by sieabahlpark on Monday July 03, 2023 @02:09PM (#36576728)
It sounds like you got some refactoring to use since you didn't namespace your own core types?
Re:Problems of C, and how Zig addresses them by stephc_int13 on Monday July 03, 2023 @02:29PM (#36577023)
I think that "namespacing" basic types such as u32 is completely unecessary.

In what world would an u32_MYLIB would be different than an u32_SOMELIB?

Basic types are common enough.

Re:Problems of C, and how Zig addresses them by pavlov on Monday July 03, 2023 @03:41PM (#36577857)
The preprocessor doesn’t know that u32 defined in foo.h is the same type as u32 defined in bar.h. So you’ll get an error when importing both.
Re:Problems of C, and how Zig addresses them by pornel on Monday July 03, 2023 @09:01PM (#36580830)
If C made this change, it could also make it legal to redefine u32 etc as appropriate integer types any number of times without erring.
Re:Problems of C, and how Zig addresses them by saagarjha on Monday July 03, 2023 @09:17PM (#36580942)
foo.h defines i64 as “long” and bar.h defines it as “long long”. Now what?
Re:Problems of C, and how Zig addresses them by kevin_thibedeau on Monday July 03, 2023 @11:37PM (#36581911)
This would break legacy code. I had one employer with a bool type that was a 32-bit integer because of obscure alignment issues. This is why _Bool exists and the bool typedef has to be brought in explicitly with stdbool. You can't just go and usurp popular short type names. The standard reserved *_t and _[A-Z].+ for this purpose. People have been writing portable code with the expectation that future standards aren't going violate that promise and break things.
Re:Problems of C, and how Zig addresses them by alexvoda on Friday July 07, 2023 @11:19AM (#36633061)
This is just one of the reasons that new languages that dispense with outdated assumptions and insted make assumptions more suitable to our times are a good thing. C and C++ are really old and some things can not be fixed with libraries.
Re:Problems of C, and how Zig addresses them by flohofwoe on Monday July 03, 2023 @02:21PM (#36576910)
C doesn't have namespaces.

The only sane way to deal with name collisions is either to use C stdlib types in library APIs (e.g. uint8_t), or use a library specific prefix (e.g. mylib_u8) - which is of course even more awkward than just using the standard uint8_t.

Re:Problems of C, and how Zig addresses them by naasking on Monday July 03, 2023 @04:52PM (#36578661)
A prefix and a namespace aren't really that different in practice.
Re:Problems of C, and how Zig addresses them by staunton on Monday July 03, 2023 @06:31PM (#36579669)
They are different. Namespaces are syntactically enforced and you can opt-in or out to names. To have syntactically validated qualified access.

Naming might go well and have the same utility, but you never know what evil things are going on in all those headers, redefining each other's symbols and yours.

Re:Problems of C, and how Zig addresses them by naasking on Monday July 03, 2023 @11:23PM (#36581805)
You seem to be focusing on specific problems with C/C++. I don't really care about that, all I'm saying is that prefixing names are equivalent to placing them within a namespace, in practice, and theoretically come to think of it. You can easily define a bijection between namespaced symbols and prefixed symbols. Requiring the full prefixes are simply a tad more verbose, essentially equivalent to using a fully qualified name for symbol.
Re:Problems of C, and how Zig addresses them by pjmlp on Tuesday July 04, 2023 @02:01AM (#36582757)
Same reasoning applies to new keywords.
Re:Problems of C, and how Zig addresses them by pjmlp on Tuesday July 04, 2023 @02:00AM (#36582752)
They added new keywords just fine, even if it needs a trasition phase to go through them.