4 ms·
Variable-length arrays are great for printf-like functions.
by binarycrusader 14y ago
Variable-length arrays are great for printf-like functions.
- kevinnk 14y agoHow so? Do you mind giving an example of a printf like function that needs variable length arrays?
- binarycrusader 14y agoI wouldn't call it a "need", more like "occasionally desirable". The short version is that it's a convenient method of letting the compiler handle resource management when you have a variable number of values and sufficient stack space. As others pointed out, it's particularly handy for multi-dimensional arrays. There are also some possible applications here: http://gustedt.wordpress.com/2011/01/13/vla-as-function-arguments/ http://gustedt.wordpress.com/2011/01/13/vla-as-function-argu... In fairness, I've used them only rarely, but those few times I've used them have saved me a bit of grief. I could easily live without them if required...
- nitrogen 14y agoAre you perhaps thinking of variable length argument lists?
- binarycrusader 14y agoNot quite; those are handy too. Admittedly, varargs is more useful than vla, but vla can be useful for these functions as well.