C9X Revision Proposal ===================== WG14/N682 (J11/97-045) WG14/N682 (J11/97-045) Title: Suggested edits for C9X Draft 9 section 6.5.3 Author: Tom MacDonald and Bill Homer Author Affiliation: Cray Research, an SGI company Postal Address: Cray Research Park 655F Lone Oak Drive Eagan, MN 55121 USA E-mail Address: tam@cray.com homer@cray.com Document Number: WG14/N682 (J11/97-045) Telephone Number: +1-612-683-5818 Fax Number: +1-612-683-5307 Sponsor: J11 Date: 08-MAY-1997 Proposal Category: XX Editorial change/non-normative contribution __ Correction __ New feature __ Addition to obsolescent feature list __ Addition to Future Directions __ Other (please specify) Change of current behavior Area of Standard Affected: __ Environment XX Language __ Preprocessor __ Library __ Macro/typedef/tag name __ Function __ Header __ Other (please specify) ______________________________ Prior Art: N/A Target Audience: all C programmers Related Documents (if any): NONE Proposal Attached: XX Yes __ No, but what's your interest? Abstract: Edits for C9X Draft section 6.5.3 ======================= Cover sheet ends here ============== The intent is to improve the flow of the section. 1. Move the paragraphs in 6.5.3 that define the semantics of restrict (#6 through #11 in c9xd9-pre3) into a new subsection 6.5.3.1, entitled "Formal definition of restrict", and place this new subsection after the first two examples. 2. In place of those five moved paragraphs, put the following new paragraph (so it will follow the paragraph about volatile, #5 in c9xd9-pre3): An object that is referenced through a restrict-qualified pointer has a special association with that pointer. This association, defined in 6.5.3.1 below, requires that all references to that object shall use, directly or indirectly, the value of that pointer. For example, a statement that assigns a value returned by malloc to a single pointer establishes this association between the allocated object and the pointer. The intended use of the restrict qualifier (like the register storage class) is to promote optimization, and deleting all instances of the qualifier from a conforming program does not change its meaning (i.e., observable behavior). 3. Revise and add to the existing examples 3 and 4, and move them into a new Examples section following the new section 6.5.3.1. That section should read: Examples 3. The file scope declarations int * restrict a; int * restrict b; extern int c[]; assert that if an object is referenced using the value of one of a, b, or c, then it is never referenced using the value of either of the other two. 4. The function parameter declarations void f(int n, int * restrict p, int * restrict q) { while ( n-- > 0 ) *p++ = *q++; } assert that, during each execution of the function, if an object is referenced through one of the pointer parameters, then it is never referenced through the other. The benefit of the restrict qualifiers is that they enable a translator to make an effective dependence analysis of function f without examining any of the calls of f in the program. The cost is that the programmer must examine all of those calls to ensure that none give undefined behavior. For example, the second call of f in g has undefined behavior because each of d[1] through d[49] is referenced through both p and q. void g(void) { extern float d[100]; f(50, d+50, d); /* defined behavior */ f(50, d+1, d); /* undefined behavior */ } 5. The function parameter declarations void h(int n, int * const restrict p, int * const q, int * const r) { int i; for ( i=0; i