This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: pure / const on function "return"ing an array?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: tfogal at sci dot utah dot edu
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 17 Jan 2011 23:56:56 +0000
- Subject: Re: pure / const on function "return"ing an array?
- References: <auto-000024304812@sci.utah.edu>
On 17 January 2011 23:04, tom fogal wrote:
> I have a function with this prototype:
>
> ?void to_3d(hsize_t index, const hsize_t dims[3], hsize_t outdex[3]);
>
> The effect of the function is to store appropriate values in the
> "outdex" array. ?It does not read or write global memory.
>
> I would like to mark this as __attribute__((const)), but it doesn't
> quite fit the definition, as it's a void function. ?Obviously I can't
> just change it to make `outdex' the return value, since outdex is an
> array.
Isn't outdex actually a pointer? That's another reason the function
can't be marked const.
> Is there anything else I could do in such a situation?
If the array bounds are fixed (as in your example above) you could
change the function to return a struct with an array member, but you'd
have to replace the dims pointer parameter too, and I have no idea if
the optimizer will do anything for const functions with struct
parameters and return types.