3 ms·
I actually believe the way C works is great, as simple as it could be and it gives you power to do exactly what you want, they way you want it. I would certain
by pritovido 6y ago
I actually believe the way C works is great, as simple as it could be and it gives you power to do exactly what you want, they way you want it.
I would certainly hate(and would continue using them btw) that they remove normal pointers from C. It would be like removing s expressions from lisp.
I believe that the solution to this "mistake" is just not using c directly, using other languages to write C code for you, or use c primitives that are 100% well tested.
That is what we do, our c primitives-libraries-modules are written and tested by lisp and our own language.
It it then very easy to use that code in python or c++, swift or whatever as libraries or modules.
- WalterBright 6y agoThe proposal does not suggest removing normal pointers from C. D has these dynamic arrays, and normal pointers too. Although one sees pointers used less and less in D code.
- AnimalMuppet 6y agoMy solution is different: Don't use dynamically-allocated variable-sized buffers unless you have to. C++ gives you more tools for avoiding them than C, BTW.
- MaxBarraclough 6y ago> C++ gives you more tools for avoiding them A direct link, for the curious: https://en.cppreference.com/w/cpp/container/array https://en.cppreference.com/w/cpp/container/array As an aside, the C’s Biggest Mistake article cropped up in HN discussion 8 days ago, https://news.ycombinator.com/item?id=24373728 https://news.ycombinator.com/item?id=24373728
- saagarjha 6y agoC++ also lets you grab an array’s size via templates, FWIW.
- MaxBarraclough 6y agoDo you mean std::extent? [0] You can do the same in C if you define a macro that uses sizeof [1] This doesn't diminish the advantage of std::array, though, as it embeds the size of the array into the object, unlike when a raw array is passed and 'decays' to a pointer. [0] https://en.cppreference.com/w/cpp/types/extent https://en.cppreference.com/w/cpp/types/extent [1] https://stackoverflow.com/a/4415646/ https://stackoverflow.com/a/4415646/
- saagarjha 6y agoI mean like you can pass it through a function by using the “array syntax” when defining the parameter and making the size a template parameter. Like so: template <size_t N> void foo(int bar[N]) And this gives you the size without an additional size parameter as you’d usually need in C (of course with the limitation that the parameter now has to be a compile-time sized array).