c++ - Is it an undefined behavior to access a pointer to an empty vector element? -
this code works expected:
std::vector<unsigned char> tab; if(!&tab[0])std::cout<<"null";
but not sure if it's legal treat &tab[0]
null when vector empty.
what expecting &tab[0]
null, not if vector empty or not.
it's can pass function accepts const unsigned char*
i'm not sure if meant unitialized (vector element) or (uninitialized vector) element, example neither. it's initialized vector of 0 elements.
a.operator[n]
defined have semantics of *(a.begin()+n)
, , begin = end empty vector, you're dereferencing end iterator. behaviour undefined.
Comments
Post a Comment