This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Dimensions of array parameters


ludovic.courtes@inria.fr (Ludovic CourtÃs) writes:

>> Perhaps something like
>>
>> extern void foo (int a, int x[__attribute__ ((dim (a)))])
>>
>> could be implemented.
>
> Why use special syntax for this?  It seems to me that âint x[a]â conveys
> the exact same information.

Using special syntax permits programmers to use the preprocessor to
write code that will work both when using versions of gcc that support
this extension and when using versions of gcc, or other compilers
entirely, that do not support it.


>> This would issue an error if foo were called such that the length of
>> the x were not at least a.  A serious problem with this approach would
>> be that it is not reliable, since the caller of foo might not know the
>> length of the array being passed as a pointer.
>
> In that case the call site could just be ignored, or a âcannot determine
> array sizeâ warning could be issued.

I'm not really satisfied with that, personally.  If using this extension
does not provide any sort of guarantee, then I don't think it buys us
very much.  It merely becomes documentation.  There is some value to
documentation expressed in code, but at least for me I don't think it
has enough value to support a change to the language.  I think we need
to cross a much higher barrier for language changes than we do for,
e.g., new optimizations or new warnings.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]