

Ask HN: Strictly-typed C Implementations? - eatonphil

Is there a C compiler that does strict type-checking? For example, casting `char`s to `int`s is a compiler error or casting pointers of one type to another? Would this kind of compiler be as useful as I think it would for a certain class of errors?
======
Someone
It shouldn't be hard to hack one from clang. You want to adjust usages of
[http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html](http://clang.llvm.org/doxygen/classclang_1_1CastExpr.html).

I would keep the main code as is, and add code to generate an error after
every call that creates a cast (hacking that code into the constructors should
work, too, but given the constructor for an empty cast and the subclasses,
that will lead to lower quality error messages).

I expect you will want to allow some/all implicit casts, explicit ones from
and to void pointers, and downcasts from 'pointer to struct with first field
of type t' to 'pointer to t'.

But most importantly: what class of programming errors are you thinking of?
That class of error, IMO, either requires a daft programmer or horrendous
source code that is full of casts.

------
AnimalMuppet
Not really trying to be a pedantic jerk, but...

Kind of by definition, what you would have would not be C, so there can't be
any strictly-typed C implementations. I presume what you want is "just like C,
except". And in fact, it's fine to want that. Just be aware that it really
isn't C any more.

~~~
dllthomas
It would be a subset of C.

------
lsiebert
This sounds like something that static code analysis would handle. That said
there would be corner cases where this would be a problem, for example a
character literal is of type int, not of type char.

