Re:C99/C11 dynamic array that mimics C++'s std::vector
by pskocik on Saturday January 07, 2017 @10:29AM
(#13344560)
__typeof_ is a compile-time feature. It's like C++'s decltype. (You can make C++'s auto out of it too.) There's is a potential for code size increases with this approach, that's true. But the potential also exists with inlinable vector methods.
Re:C99/C11 dynamic array that mimics C++'s std::vector
by tines on Saturday January 07, 2017 @10:50AM
(#13344670)
Yes, but for the vector methods, you leave that decision up to the compiler which should be able to take the best route.
Re:C99/C11 dynamic array that mimics C++'s std::vector
by pskocik on Saturday January 07, 2017 @11:26AM
(#13344864)
True. However, I think in the case of the dynamic array, this effect is minor. The macros are small, and most of the time, they end up wrapped in a function anyway. But, admittedly,it doesn't scale well to very big generics, which should be always wrapped in a function. (Eventually I plan to shove a simple transpiler in front of all my C code and do this, along with namespacing, how I think it should be done.)
If so, C++ has a nice advantage in that all the type checks are at compile-time so you don't pay any more for those, and also you don't duplicate binary code with macros.