c++ - Offset from a memory address -
i reading code , came across example. don't understand why author uses offset of 1 both variables on last line. @ first glance assume illegal because referring possibly uninitialized memory area (and cause segmentation fault). head keeps telling me undefined behavior 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 1 in question. why necessary he's doing this, legal, , when should done?
it appears author wanted compare 2 characters using current global locale.
since std::collate<t>::compare
uses [low, high) 2 ranges, adding 1 address of parameters cause comparison stop after compared b. there should no invalid memory accesses.
Comments
Post a Comment