Click here to Skip to main content
15,902,938 members

Comments by Robin Cheng (HPMV) (Top 2 by date)

Robin Cheng (HPMV) 15-Aug-11 13:49pm View    
Oh and I guess it's also useful for arrays declared without explicit bound with an array literal, like in te original question :)
Robin Cheng (HPMV) 15-Aug-11 13:47pm View    
Ah I see; didn't know that before :)
I say it's a bad style because if we have C++ we have a greater flexibility of doing things. If we need a fixed sized array and want to vary the size at compile time, we could use a const int to specify the size which can later be accessed. If we need a variable sized array we could use classes like std::vector.
Personally I would suggest this only if it's out of pure convenience and used for a local array. Because this is a compile time computation and only works if the length of arr is known at compile time. This means if an array is passed to a function, the function would not know this and the aforementioned expression would not work.