
Surprising properties of C null pointer constants - ingve
https://kristerw.blogspot.com/2016/08/surprising-properties-of-c-null-pointer.html
======
jjnoakes
How much interest would there be in a cleaned up C?

A non-backward-compatible very-close-to-c dialect with a lot of these tricky
corner cases removed? Made a bit more ergonomic overall?

It would still be abi compatible and easily integrated into C projects (same
headers, declarations, etc).

I know of some more ambitious attempts at a saner C and why they failed.

But every time I write something to work with C 's legacy rules I wonder "why
can't this just be a little better".

I'm not talking new language better. Just a new dialect of C that compiler
could easily support, perhaps with a directive in a C source file. It could
even transpile to C for compilers that didn't support it.

Something like what C would be without the legacy cruft.

Would anyone use it but me?

~~~
jasonjei
The problem with this idea is C is an advanced language requiring one to be
very careful with memory (referencing, allocation, deallocation, etc). If we
are to keep C in its essence with well-defined behavior, managing memory still
seems to be part of the job description.

I think what you are describing is Rust, Go, C++11 RAII with reference
counting, Objective-C with ARC. I like to think of C as an abstraction of
assembly. Of course, the above languages often use libraries or OS APIs
implemented with C function calls (as well as having resource handles); these
library functions may not always have a nice wrapper around them.

C is a very concise, barebones and syntactically simple language. I think some
of the problem is that there is a lot of behavior that is not well-defined
resulting in different interpretations in different compilers. I think there
are proposals to make C more standardized.

I think C++11 has made great moves to being consistent across all compilers.
Having a thread library that is cross-platform, for example, is a very good
move.

~~~
jjnoakes
Nope. I'm specifically describing only the rough edges of C.

Things like defining a NULL pointer to convert from any zero value.

Nothing as ambitious as a nrw language, like I said above.

I want a modern version of exaxtly what C is, without some of these undefined
or implementation defined legacy warts.

And I understand that defining some things may make the program barely
measurably slower. Someone can opt in to raw C if they care. It could even be
in the same file... Think scoped "pragma overflow" directives that last for
the lexical scope to get raw speed by opting out of defined semantics.

~~~
stephen82
I guess what you really want is what Microsoft is trying to resolve with
Checked C in order to bridge the C gap with C++.

Here's the link if you are interested:
[https://github.com/Microsoft/CheckedC](https://github.com/Microsoft/CheckedC)

~~~
jjnoakes
I don't think so; Checked C looks to be focusing on array bounds checking and
adds new syntax, new pointer types, etc.

I want to focus on cleaning up C as it is. I don't want a new syntax or new
semantics outside of defining some/most of what is undefined today.

~~~
stephen82
I would be more than interested to see a demo code using pseudo-language to
explain exactly the concept you have in mind.

That would be more than interesting for lots of us and you never know; we
might get something out of it and why not implement it as a FOSS project?

~~~
jjnoakes
The friendly C and boring C proposals are quite close to what I'm thinking of.
I was sad to see friendly C abandoned.

I hope to find the time shortly to take a stab at something along those lines.

