Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Doesn't the compiler only complain about the type when you're doing something wrong anyway?

C is only cumbersome when you don't already have the data structures you want implemented, which is why there are usually many libraries for any one data structure you want to represent, and operations on it.

As for array bounds, it should work so long as you don't access out of bounds, and you can do that by making sure you know what you're accessing. It's not that hard - but even if you want, you can get your compiler to tell you when you do out of bounds access at runtime.



> As for array bounds, it should work so long as you don't access out of bounds, and you can do that by making sure you know what you're accessing. It's not that hard

Judging by the flood of out of bounds array accesses in shipping code over several decades, actually it is pretty hard to consistently get it right.

> even if you want, you can get your compiler to tell you when you do out of bounds access at runtime.

At the cost of making your program slower than Java. So at that point why not use a memory safe language?


> C is only cumbersome when you don't already have the data structures you want implemented, which is why there are usually many libraries for any one data structure you want to represent, and operations on it.

I suspect this is the mistake I'm making, because 90% of my time is spent writing code to do data structure manipulation. I'll look around and try to find some libraries for things, but I'm usually constrained to the ecosystem of the particular flavor of C I write (for the Arduino, which is really C++, but still). I guess most general-purpose libraries will work there too, though.

> As for array bounds, it should work so long as you don't access out of bounds, and you can do that by making sure you know what you're accessing.

No, they do work, it just takes me ages to find the correct thing to tell the compiler so it understands what I want to do. Don't get me started on the ten types of string, though :(


If you're writing C code, the right way to think about data structures in a lot of cases is that they're an optimization.

You can implement a map using an array of struct { key, value }, and O(n) search. If you keep it sorted, that becomes O(n log n). A hash table is a further optimization.

Most of the time you don't need these.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: