Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Freeing double restricted pointer?

68 views
Skip to first unread message

andrew.go...@debesys.net

unread,
Nov 5, 2012, 11:07:19 AM11/5/12
to
I have a table of string pointers, declared as follows:

char * restrict * restrict table;

Each of the strings in the table is a unique region of memory, only accessible via 'table[index]'. The array containing the string pointers is also a unique memory region, only accessible via the table variable.

At some point, I'd like to free the table. I do so via:

free(table);

This results in the following warning from gcc:

test.c:10:5: warning: passing argument 1 of ‘free’ discards ‘restrict’ qualifier from pointer target type [enabled by default]
test.c:2:13: note: expected ‘void *’ but argument is of type ‘char * restrict* restrict’


Is this expected behavior?

James Kuyper

unread,
Nov 5, 2012, 5:24:08 PM11/5/12
to
On 11/05/2012 11:07 AM, andrew.go...@debesys.net wrote:
> I have a table of string pointers, declared as follows:
>
> char * restrict * restrict table;
>
> Each of the strings in the table is a unique region of memory, only accessible via 'table[index]'. The array containing the string pointers is also a unique memory region, only accessible via the table variable.
>
> At some point, I'd like to free the table. I do so via:
>
> free(table);
>
> This results in the following warning from gcc:
>
> test.c:10:5: warning: passing argument 1 of �free� discards �restrict� qualifier from pointer target type [enabled by default]
> test.c:2:13: note: expected �void *� but argument is of type �char * restrict* restrict�
>
>
> Is this expected behavior?

Passing an argument to a function is subject to the same constraints as
would apply to an assignment of that argument to the corresponding
parameter (6.5.2.2p2). The permitted combinations of source and
destination types for assignment are listed in 6.5.16.1p1. The fourth
combination is the one that comes closest to this case: it allows the
source and destination to both be pointer types, with either one a
pointer to void, but it requires that the destination type have all of
the same qualifiers as the source. 'restrict' is a qualifier, so passing
a restrict qualified pointer to a function when the corresponding
parameter doesn't have the same qualifiers violates that constraint. At
least one diagnostic message is required when processing a program
containing any syntax errors or constraint violations - you got two
messages, so technically you could say that the second one was
unexpected, but the standard never prohibits the generation of extra
messages


0 new messages