4 ms·
I don't really see how variable length arrays save time? Those seem like a feature that belongs in C++ but definitely not in C imho. However, what I like to se
by Aardwolf 14y ago
I don't really see how variable length arrays save time? Those seem like a feature that belongs in C++ but definitely not in C imho.
However, what I like to see in C are "//" style comments, declaring variables at other places than start of scope, the integer types with bit size specified, etc...
But the VLA's? They're created on the stack, right? So you'd need malloc for large ones anyway.
What actually would save time (for the coder of course) in C, imho, would be a way to automatically clean up resources no matter where you exit a scope or function. Something like destructors do in C++. E.g. if you could type something like "onleave free(myresource);" which would execute what you type after "onleave" whenever the scope exits.
- brigade 14y agoHowever, what I like to see in C are "//" style comments, declaring variables at other places than start of scope, the integer types with bit size specified, etc... All of those are already in C99... And malloc() takes more time than subtracting a variable from the stack pointer. Though VLAs have pitfalls so you probably don't want to use them outside of throw-away code anyway.
- lobster_johnson 14y ago> However, what I like to see in C are "//" style comments, declaring variables at other places than start of scope Good news, those are both part of C99 (http://en.wikipedia.org/wiki/C99 http://en.wikipedia.org/wiki/C99), which is supported by both GCC and Clang.
- cjh_ 14y agoRegarding your 'onleave' idea; go has a similar construct called defer [1], it is exactly what you are talking about and (imo) is a really elegant way of dealing with cleanup. [1]http://golang.org/doc/effective_go.html#defer http://golang.org/doc/effective_go.html#defer