I saw in the code next statement:
SomeType someVar[1];
Later someVar
is used as a pointer to SomeType
. Why would one
The first can be treated as a pointer to a possibly uninitialized SomeType
(initialized if it's a non-POD type). The second is just a dangling pointer.
SomeType someVar[1];
someVar[0]; //valid
*someVar; //valid
vs
SomeType* someVar;
someVar[0]; //invalid
*someVar; //invalid
For the second one to work, you'd need to make it point to something valid, so either an existing object (so then there's no point in having the pointer there), or to a new object allocated with new
, in which case there's the downside that you have to call delete
yourself.