Answers to Washu's quiz #1?

Started by
29 comments, last by MaulingMonkey 15 years, 2 months ago
Quote:Original post by Oxyd
Quote:Original post by Washu
At the point p+11 is performed, the behavior of the application is completely undefined.


At that point? I thought that if the behaviour of a single part in the whole program is undefined, the behaviour of the whole program is undefined -- including everything before the first line that causes UB. It doesn't even have to compile if I understand it right.


Doesn't sound too off, especially given the penchant for compilers to reorder statements for optimization purposes. More accurate might be "At the point that p+11 will be performed at some point with p having no more than 10 elements at the later point, the behavior of the application is completely undefined.", but that's a bit awkward phrasing -- and more likely to confuse than inform.

Since this code can throw an exception from new[] (namely std::bad_alloc), however, we can't be certain if p+11 will be executed until the completion of that statement, and thus I have reason to believe that this code must at least compile -- although there might be clauses in the C++ standard that allow any additional diagnostic errors that the implementor desires that I'm forgetting about which would allow the compile to fail while compiling with the C++ standard all the same.

This topic is closed to new replies.

Advertisement