Topic: 4.4: Amendment: pointers to similar arrays
Author: "Krzysztof elechowski" <krixel@qed.pl>
Date: Sat, 25 Feb 2006 10:29:47 CST Raw View
QUOTATION
4.4. says the following about standard pointer conversions:
A conversion can add cv-qualifiers at levels other than the first in
multi-level pointers, subject to the following rules:56)
Two pointer types T1 and T2 are similar if there exists a type T and integer
n > 0 such that:
T1 is cv1,0 pointer to cv1,1 pointer to ... cv1,n-1 pointer to cv1,n T
and
T2 is cv2,0 pointer to cv2,1 pointer to ... cv2,n-1 pointer to cv2,n T
where each cvi, j is const, volatile, const volatile, or nothing. The
n-tuple of cv-qualifiers after the first in a pointer type, e.g., cv1,1,
cv1,2, ..., cv1,n in the pointer type T1, is
called the cv-qualification signature of the pointer type. An expression of
type T1 can be converted to type T2 if and
only if the following conditions are satisfied:
- the pointer types are similar.
- for every j > 0, if const is in cv1, j then const is in cv2, j, and
similarly for volatile.
- if the cv1, j and cv2, j are different, then const is in every cv2,k for 0
< k < j.
PROBLEM STATEMENT
4.4. handles conversions of pointers to pointers but it does not support
converting pointers to arrays. The following example is ill-formed:
int const *const (*foo(int *p_f[][02]))[02]{ return p_f; }
In plain English: It is illegal to convert a pointer to an array of pointers
to a pointer to a constant array of constant pointers.
A real-world example:
void printc(int const *const p_f[][02]);
void print(int *p_f[][02]) { return printc(p_f); } // ill-formed
They are ill-formed because the types of int const *[02] and int *[02] are
different.
It should not be ill-formed because if it were allowed it would not cause
any compromise.
PROPOSED RESOLUTION
Add recurrence over arrays to clause 4.4, as follows:
A conversion can add cv-qualifiers at levels other than the first in
multi-level pointers, subject to the following rules:56)
Two pointer types T1 and T2 are similar if there EXIST TYPES T3 AND T4 and
integer n > 0 such that:
T3 IS IDENTICAL TO T4 OR BOTH ARE ARRAYS OF SIMILAR POINTERS
T1 is cv1,0 pointer to cv1,1 pointer to ... cv1,n-1 pointer to cv1,n T3
and
T2 is cv2,0 pointer to cv2,1 pointer to ... cv2,n-1 pointer to cv2,n T4
where each cvi, j is const, volatile, const volatile, or nothing. The
n-tuple of cv-qualifiers after the first in a pointer type, e.g., cv1,1,
cv1,2, ..., cv1,n in the pointer type T1, is
called the cv-qualification signature of the pointer type. An expression of
type T1 can be converted to type T2 if and
only if the following conditions are satisfied:
- the pointer types are similar.
- for every j > 0, if const is in cv1, j then const is in cv2, j, and
similarly for volatile.
- if the cv1, j and cv2, j are different, then const is in every cv2,k for 0
< k < j.
- T3 IS IDENTICAL TO T4 OR THE POINTERS CONTAINED IN T3 CAN BE CONVERTED TO
THE POINTERS CONTAINED IN T4
Please consider this amendment for the next edition of the Standard.
Christopher
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]