Liste des Groupes | Revenir à cl c |
Bart <bc@freeuk.com> writes:But that is a separate thing. Suppose T was an alias for 'const int'. Then:
[...]I think 'const' is confusing for similar reasons that VLAs can be bothSure. For example, given
confusing and awkward to implement.
>
That's because both really apply to /types/, not directly to variables.
const int n = 42;
n is of type `const int`, and &n is of type `consts int*`. Of course
that implies that n itself is const.
I'm not sure what's so confusingVLAs are mostly linked to stack allocation. But that only applies when the array is at the top level of the type spec, in the same why that it's the top-level 'const' that would determine whether storage is read-only - if declaring a variable.
about that. If const applied *directly* to variables, it's hard to see
how something like &n could be treated consistently.
"const" has to apply to types anyway. Are you suggesting that it should
have an additional meaning when applied to variables? What would be the
advantage of that?
So both const and a VLA can specified deep inside a type-spec, whereIt declares *and defines* (allocates storage for) a pointer to a VLA.
there may be no storage allocated, inside a cast for example, but
here's a simpler one:
>
int n;
const int (*A)[n];
>
This declares a pointer to a VLA, so no storage is allocated for the
VLA. (I'm not even sure how you'd allocate it in the program, given
that VLAs normally go on the stack.)
You could allocate the array any way you like. For example:
Les messages affichés proviennent d'usenet.