J3/06-280r1
To: J3
From: Bill Long
Subject: Removal of the restrict keyword in the C header file, FDesc.h
Date: 15 August 2006
Reference: J3/04-371, J3/05-159, J3/05-271.
1. Introduction
The restrict keyword was added to function prototypes in the C header
file, FDesc.h, (in paper J3/05-159) at the suggestion of members of
J11; however, subsequently it was removed (in paper J3/05-271). This
paper provides a justification for the removal of the restrict
keyword. (FDesc.h provides C prototypes for functions implementing a
mechanism that allows arguments that are pointers, allocatables, or
assumed-shape arrays to be interoperable.)
2. Discussion
The restrict keyword provides semantic information to the C compiler that
allows for certain optimizations based on the premise that a given object
cannot be changed through another pointer. These optimizations are
particularly advantageous for loop transformations. However the functions in
FDesc.h are assessors, either setting or getting information from an
internal compiler data object, and no significant optimizations can be
obtained by the usage of restrict in these functions.
Furthermore, the presence of restrict imposes an unnecessary burden on the
programmer using these functions. A given compiler may not support
restrict (as it was recently introduced in the C99 standard and is not in
the C++ standard) or it may only be accessible through special compiler
options. More importantly, the programmer may not understand the meaning
of restrict and unwittingly break a function's prototype by aliasing two
pointers. For example, in creating a descriptor object for a rank one
array, it may be that the shape and stride arrays contain the same value,
so the programmer may pass the same array to a creation routine, e.g.,
FDesc_Assumed_Create.
3. Conclusion
Because the potential for optimizations through the usage of restrict
is minor and it may cause an unneeded burden on the programmer, the
restrict keyword was removed from FDesc.h in paper J3/05-271.