Liste des Groupes | Revenir à cl c |
On 5/13/25 22:37, Keith Thompson wrote:
>Tim Rentsch <tr.17687@z991.linuxsc.com> writes:>
>Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>Tim Rentsch <tr.17687@z991.linuxsc.com> writes:>
>Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:>
[...]
>>My personal interpretation is that this:>
>
void func(int arr[static 5]) {
}
>
int main(void) {
int arr[10];
func(arr+5); // OK
// func(arr+6); // UB
}
>
is valid, because, for example, the last 5 elements of a 10-element
array object can be treated as a 5-element array object. gcc seems
to agree, based on the fact that it warns about func(arr+6) but
not about func(arr+5).
>
This is a fundamental part of my mental model of C, but in a few
minutes of searching I wasn't able to find explicit wording in the
standard that supports it.
In N1570, 6.7.6.3 p7.
Did you mean to imply that that paragraph supports (or refutes) my
statement? [...]
No. I posted the reference to say that the cited paragraph supports
the conclusion that 'func(arr+6)' is undefined behavior.
...
>>To me it seems obvious that 6.7.6.3 p7 is meant to cover the>
case of 'func(arr+6)' as being undefined behavior.
But that's not the question I was addressing. My question is whether
func(arr+5) has defined behavior, based on whether or not a+5 points to
the *first element* of an array.
Tim - [...]
Les messages affichés proviennent d'usenet.