Earlier quoted context omitted.
The problem with let's get rid of NULL is that it's a real, required state. The vast majority of computing is actually not binary: any real input generally has at least 3 possible states: not set, true and false. In practice really 4 because "indeterminate" is a reasonable error condition you'd like to know about. And it keeps increasing anyway: e.g. not set has subcategories: not set due to lack of user input, not s…
What you are describing is option types, which are an entirely valid and very useful construct that helps make programs more rather than less reliable. But you need proper language type system support and compile-time enforcement to make it work, and C does neither of those.
Linux eliminates the strncpy API after six years of work, 360 patches
61–70 of 340 posts
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#62Earlier quoted context omitted.
I think it was NULL itself. It was a long way until we realised we don't want invalid values and could use the type system to help us use special values safely.
Genuinely curious, how would you handle cases where a value is unset without NULL? This is a legitimate case that happens a lot in eg data modeling
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#63I wonder, why not use a string buffer paired with its length? For example, maybe use struct that has char pointer, and 2 ints (occupied length + total buffer length). Almost like c++'s std::string. This null terminator thing really sucks, it's potentially insecure and often unperformant.
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#64Earlier quoted context omitted.
AGI might. AI? No way. See, AI was trained on existing data - on all that existing C code out there (sure, and also on all the papers and articles saying what was wrong with that C code). Those bugs are in the training data , and often not marked as bugs. So when AI generates C code, is it going to avoid making the mistakes that human code made? No, it's going to generate the kind of code it was trained on. How could…
> See, AI was trained on existing data - on all that existing C code out there (sure, and also on all the papers and articles saying what was wrong with that C code). Those bugs are in the training data, and often not marked as bugs. So when AI generates C code, is it going to avoid making the mistakes that human code made? No, it's going to generate the kind of code it was trained on. How could it be otherwise? The…
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#65Earlier quoted context omitted.
I think it was NULL itself. It was a long way until we realised we don't want invalid values and could use the type system to help us use special values safely.
Genuinely curious, how would you handle cases where a value is unset without NULL? This is a legitimate case that happens a lot in eg data modeling
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#66I wonder, why not use a string buffer paired with its length? For example, maybe use struct that has char pointer, and 2 ints (occupied length + total buffer length). Almost like c++'s std::string. This null terminator thing really sucks, it's potentially insecure and often unperformant.
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#67Huh. Whenever I've been asked to review C code, I always looked for strncpy and always found a bug with it.
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#68Earlier quoted context omitted.
Genuinely curious, how would you handle cases where a value is unset without NULL? This is a legitimate case that happens a lot in eg data modeling
The way we do it in modern languages with things like std::optional and even that is not the best example.
You basically end up with null/0 don’t you?
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#69Wouldn't this work be extremely easy to implement with an LLM coder?
Re: Linux eliminates the strncpy API after six years of work, 360 patches
#70What happens if you turn a job like that over to Claude Code? A mess? Good results? Code bloat? Worth trying on existing C programs.