I was reading some code and I came across this example. What I don't understand is why the author uses an offset of 1 from both variables on the last line. At first glance I would assume this is illegal because it is referring to a possibly uninitialized memory area (and it could cause a segmentation fault). My head keeps telling me undefined behavior but is this really so?
static bool lt(wchar_t a, wchar_t b)
{
const std::collate<wchar_t>& coll =
std::use_facet< std::collate<wchar_t> >(std::locale());
return coll.compare(&a, &a+1, &b, &b+1) < 0;
}
The last line is the one in question. Why is it necessary that he's doing this, is it legal, and when should it be done?