user58697
user58697

Reputation: 7923

Is undefined versus undefined behavior

The cppreference wording on front and back is surprisingly (at least for me) asymmetric.

front:

Calling front on an empty container is undefined.

back

Calling back on an empty container causes undefined behavior.

I know I am supposed to ask only one question, but still,

  1. Why it is different?, and
  2. What is the difference between is undefined and causes undefined behavior?

Upvotes: 0

Views: 131

Answers (2)

Amit
Amit

Reputation: 1160

In C++, there is no difference between "undefined" and "undefined behavior." Both terms refer to the same concept: a situation in which the standard does not specify the expected outcome of a certain operation.

Upvotes: 2

Alan
Alan

Reputation: 1

What is the difference between is undefined and causes undefined behavior?

They have the same meaning here.


Why it is different?,

Most likely because the page has been written by different authors or/and has not been updated for quite some time. Still, both are intended to mean the same thing.


Update

The page has now been updated to make the documentation language more consistent. In particular, now front says:

Calling front on an empty container causes undefined behavior.

Upvotes: 1

Related Questions