3 ms·
And they still haven't adopted the C++ const-correctness rules (for pointers to pointers to ...), which really do help in writing correct code, and correct code
by wnoise 15y ago
And they still haven't adopted the C++ const-correctness rules (for pointers to pointers to ...), which really do help in writing correct code, and correct code that has flavor of C89.
- erydo 15y agoWhat? C has those const rules. The type "int const* const*" is valid C. The differences are primarily that in C you can't use a const symbol in a place where a constant expression is expected (e.g. initializing another const, or a statically sized array). But you can absolutely do const-correct code in C.
- kzrdude 15y agoThe issue is laid out here by C-FAQ: http://c-faq.com/ansi/constmismatch.html http://c-faq.com/ansi/constmismatch.html
- wnoise 15y agoIt has a set of const-correctness rules. They're much simpler than the C++ rules. While they handle the simple cases perfectly well, they forbid some assignments that really can't get you in trouble, and would be quite useful in practice. In particular, while "int const * const * " exists, it can't be assigned from an "int * * ", even though this is sound. This makes it hard to write const-correct functions handling 2-d arrays.[1] kzrdude's link shows how they have to rule out certain constructs that are not obviously wrong. It doesn't explain how the C++ assignment compatibility rules allow more, while still being sound, but that's a bit much to expect from a C FAQ, particularly as the C++ rules are somewhat involved. (I can't find a decent reference that explains the rules well. I found one about six months ago, but didn't save it, as I don't professionally use C++.) [1]: Preemptive pedanticism: Yes, there are difference between C arrays and pointers, the expression types merely decay in the right contexts. But if I'm using [] to dereference, they're being used as arrays.