Spiros Bousbouras wrote:
Is there a way to mimick restricted pointers
using array syntax ? So I'm looking for something
to add to a statement such as "int arr[50]" which
will tell the compiler that I will only access the contents of the
array through arr. If I was using
pointers I would do for example
int * restrict p = malloc(50 * sizeof(int))
Is there a way to do the same thing using
arrays ?
Are you sure this is meaningful? (I can't even convince
myself that your example is meaningful, so maybe there's
something I haven't grasped ...)
If the array identifier has internal linkage (file-scope
static) or no linkage (auto or block-contained static), the
compiler can see for itself whether you aim any other pointers
at it or at its interior. If you pass a pointer to the array
to some other function the compiler pretty much has to assume
that the other function may derive further pointers from it and
maybe return those aliases to you, but usually that's *why* you
call such a function: `p = strchr(string, '\n')' is *intended*
to create another access path.
If the array identifier has external linkage, I'm pretty
much certain that `restrict' is meaningless. Formally, the
`arr' in Module 1 and the `arr' in Module 2 are different
identifiers; the process of linkage makes these two identifiers
refer to the same object. So the mere existence of one of the
pair makes it impossible for the other to be "the one and
only," and vice versa. What would `restrict' mean?
... but I must confess that my grasp of `restrict' is
somewhat, er, restricted in scope.
--
Er*********@sun.com