News for hackers. Stuff that matters.
Re:I write games in C (yes, C) by ninkendo on Saturday February 07, 2026 @03:55PM (#46927903)
C's string handling is so abominably terrible that sometimes all people really need is "C with std::string".

Oh, and smart pointers too.

And hash maps.

Vectors too while we're at it.

I think that's it.

Re:I write games in C (yes, C) by teo_zero on Saturday February 07, 2026 @04:31PM (#46928301)
I agree on the former two (std::string and smart pointers) because they can't be nicely implemented without some help from the language itself.

The latter two (hash maps and vectors), though, are just compound data types that can be built on top of standard C. All it would need is to agree on a new common library, more modern than the one designed in the 70s.

Re:I write games in C (yes, C) by ninkendo on Saturday February 07, 2026 @05:32PM (#46928885)
I think a vec is important for the same reason a string is… because being able to properly get the length, and standardized ways to push/pop from them that don’t require manual bounds checking and calls to realloc.

Hash maps are mostly only important because everyone ought to standardize on a way of hashing keys.

But I suppose they can both be “bring your own”… to me it’s more that these types are so fundamental and so “table stakes” that having one base implementation of them guaranteed by the language’s standard lib is important.

Re:I write games in C (yes, C) by uecker on Saturday February 07, 2026 @04:53PM (#46928507)
why not std::string?
Re:I write games in C (yes, C) by teo_zero on Saturday February 07, 2026 @05:23PM (#46928800)
You can surely create a std::string-like type in C, call it "newstring", and write functions that accept and return newstrings, and re-implement the whole standard library to work with newstrings, from printf() onwards. But you'll never have the comfort of newstring literals. The nice syntax with quotes is tied to zero-terminated strings. Of course you can litter your code with preprocessor macros, but it's inelegant and brittle.
Re:I write games in C (yes, C) by krapp on Saturday February 07, 2026 @07:20PM (#46929866)
Re:I write games in C (yes, C) by pjmlp on Sunday February 08, 2026 @03:42AM (#46932534)
If only WG14 added something similar to C.

Yes, SDS exists, however vocabulary types are quite relevant for adoption at scale.

Re:I write games in C (yes, C) by tialaramex on Sunday February 08, 2026 @12:11PM (#46936277)
Because C wants to run on bare metal, an allocating type like C++ std::string (or Rust's String) isn't affordable for what you mean here.

I think you want the string slice reference type, what C++ called std::string_view and Rust calls &str. This type is just two facts about some text, where it is in memory and how long it is (or equivalently where it ends, storing the length is often in practice slightly faster in real machines so if you're making a new one do that)

In C++ this is maybe non-obvious because it took until 2020 for C++ to get this type - WG21 are crazy, but this is the type you actually want as a fundamental, not an allocating type like std::string.

Alternatively, if you're not yet ready to accept that all text should use UTF-8 encoding, -- and maybe C isn't ready for that yet - you don't want this type you just want byte slice references, Rust's &[u8] or C++ std::span<char>

Re:I write games in C (yes, C) by direwolf20 on Saturday February 07, 2026 @05:11PM (#46928657)
It's a class, so it doesn't work in C.
Re:I write games in C (yes, C) by uecker on Saturday February 07, 2026 @05:17PM (#46928726)
Sure, but you can have a similar string abstraction in C. What would you miss? The overloaded operators?
Re:I write games in C (yes, C) by direwolf20 on Saturday February 07, 2026 @07:31PM (#46929951)
Automatic memory accounting — construct/copy/destruct. You can't abstract these in C. You always have to call i_copied_the_string(&string) after copying the string and you always have to call the_string_is_out_of_scope_now(&string) just before it goes out of scope
Re:I write games in C (yes, C) by uecker on Sunday February 08, 2026 @01:37AM (#46931860)
This seems orthogonal to std::string. People who pick C do not want automatic memory management, but might want better strings.
Re:I write games in C (yes, C) by direwolf20 on Sunday February 08, 2026 @05:01AM (#46932933)
Automatic memory management is literally what makes them better
Re:I write games in C (yes, C) by uecker on Sunday February 08, 2026 @05:53AM (#46933187)
For many string operations such as appending, inserting, overwriting etc. the memory management can be made automatic as well in C, and I think this is the main advantage. Just automatic free at scope end does not work (without extensions).
Re:I write games in C (yes, C) by direwolf20 on Sunday February 08, 2026 @11:11AM (#46935562)
You can make strings (or bignums or matrices) more convenient than the C default but you can never make them as convenient as ints, while in C++ you can.
Re:I write games in C (yes, C) by uecker on Sunday February 08, 2026 @11:44AM (#46935973)
Yes, but I do not think this is a good thing. A programming language has to fulfill many requirements, and convenience for the programmer is not the most important.
Re:I write games in C (yes, C) by direwolf20 on Sunday February 08, 2026 @05:37PM (#46939290)
Empirically it is. All the most used languages are the most convenient ones.
Re:I write games in C (yes, C) by WalterBright on Saturday February 07, 2026 @05:12PM (#46928673)
When I developed D, a major priority was string handling. I was inspired by Basic, which had very straightforward, natural strings. The goal was to be as good as Basic strings.

And it wasn't hard to achieve. The idea was to use length delimited strings rather than 0 terminated. This meant that slices of strings being strings is a superpower. No more did one have to constantly allocate memory for a slice, and then keep track of that memory.

Length-delimited also super speeded string manipulation. One no longer had to scan a string to find its length. This is a big deal for memory caching.

Static strings are length delimited too, but also have a 0 at the end, which makes it easy to pass string literals to C functions like printf. And, of course, you can append a 0 to a string anytime.

Re:I write games in C (yes, C) by jfaulken on Saturday February 07, 2026 @06:22PM (#46929388)
Just want to off-topic-nerd-out for a second and thank you for Empire.
Re:I write games in C (yes, C) by WalterBright on Saturday February 07, 2026 @06:48PM (#46929621)
You're welcome!

One of the fun things about Empire is one isn't out to save humanity, but to conquer! Hahahaha.

BTW, one of my friends is using ClodCode to generate an Empire clone by feeding it the manual. Lots of fun!

Re:I write games in C (yes, C) by 9rx on Saturday February 07, 2026 @08:02PM (#46930219)
Add concurrency and you more or less came up with same list C's own creator came up when he started working on a new language.
Re:I write games in C (yes, C) by saidinesh5 on Sunday February 08, 2026 @12:33AM (#46931601)
And constructors and destructors to be able to use those vectors and hash maps properly without worrying about memory leaks.

And const references.

And lambdas.

Re:I write games in C (yes, C) by pjmlp on Sunday February 08, 2026 @03:40AM (#46932524)
Yeah, WG14 has had enough time to provide safer alternatives for string and arrays in C, but that isn't a priority, apparently.
Re:I write games in C (yes, C) by tialaramex on Sunday February 08, 2026 @08:35AM (#46934061)
The C++ std::string is both very complicated mechanically and underspecified, which is why Raymond Chen's article about std::string has to explain three different types (one for each of the three popular C++ stdlib implementations) and still got some details wrong resulting in a cycle of corrections.

So that wouldn't really fit C very well and I'd suggest that Rust's String, which is essentially just Vec<u8> plus a promise that this is a UTF-8 encoded string, is closer.

Re:I write games in C (yes, C) by klaussilveira on Sunday February 08, 2026 @03:28PM (#46938191)