Saturday, February 1, 2014

Address one past the end of array - is this syntax a valid C++?

Newsgroup: comp.lang.c++

Subject: Address one past the end of array - is this syntax a valid C++?

From: Peter <pilarp@...>

Date: Sat, 1 Feb 2014 09:23:39 -0800 (PST)



Assume we have an array:



int arr[5];



It's legal to refer to address arr + 5, but, of course, illegal to refer to element arr[5] as it's not part of the array. However, arr + n is equivalent to &arr[n]. My question is: does this equivalence also hold for an edge case of

n = 5 (or, generally, n equal to number of elements of array)?



While there's nothing wrong with arr + 5, &arr[5] looks highly suspicious: it looks like in the first step arr[5] is evaluated (which introduces an undefined behaviour) which would mean the expression as a whole is undefined. Does the equivalence still hold in this special case?







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://ift.tt/1i4Tpfr

View all the progranning help forums at:

http://ift.tt/1dP9txN

No comments:

Post a Comment