You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Kamesh Jayachandran <ka...@collab.net> on 2006/10/12 11:08:02 UTC
[PATCH]simple(for me only? not sure) typecasting
Hi All,
I found the following snippet in subversion/libsvn_subr/sorts.c.
<snip>
svn_sort_compare_paths(const void *a, const void *b)
{
const char *item1 = *((const char * const *) a);
const char *item2 = *((const char * const *) b);
return svn_path_compare_paths(item1, item2);
}
</snip>
I feel it is easier to understand 'const char *item1 = *((const char **)
a);' than 'const char *item1 = *((const char * const *) a);'.
Attaching the patch/log for the same.
With regards
Kamesh Jayachandran
Re: [PATCH]simple(for me only? not sure) typecasting
Posted by Philip Martin <ph...@codematters.co.uk>.
Kamesh Jayachandran <ka...@collab.net> writes:
> Daniel Rall wrote:
>> On Thu, 12 Oct 2006, Kamesh Jayachandran wrote:
>>>
>>> <snip>
>>> svn_sort_compare_paths(const void *a, const void *b)
>>> {
>>> const char *item1 = *((const char * const *) a);
>>> const char *item2 = *((const char * const *) b);
>>> return svn_path_compare_paths(item1, item2);
>>> }
>>> </snip>
>>> I feel it is easier to understand 'const char *item1 = *((const
>>> char **) a);' than 'const char *item1 = *((const char * const *)
>>> a);'.
>>
>> This patch changes the semantics of those statements.
>>
> Agreed. Can someone point me to the docs where I can understand the
> typecasting of the above nature?
'const void *' is 'pointer to const void'. The original code casts
this to 'pointer to const FOO' where FOO is 'pointer to const char'
while your new code casts to 'pointer to non-const FOO'. Your code
casts away const, and while it is valid to do that it is likely that
compilers and code checkers will issue warnings.
$ cat z.c
void f(const void *p) { const char *q = *((const char **)p); }
$ gcc -c -Wcast-qual z.c
z.c: In function 'f':
z.c:1: warning: cast discards qualifiers from pointer target type
--
Philip Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH]simple(for me only? not sure) typecasting
Posted by Kamesh Jayachandran <ka...@collab.net>.
Daniel Rall wrote:
> On Thu, 12 Oct 2006, Kamesh Jayachandran wrote:
>
>
>> Hi All,
>> I found the following snippet in subversion/libsvn_subr/sorts.c.
>>
>> <snip>
>> svn_sort_compare_paths(const void *a, const void *b)
>> {
>> const char *item1 = *((const char * const *) a);
>> const char *item2 = *((const char * const *) b);
>> return svn_path_compare_paths(item1, item2);
>> }
>> </snip>
>> I feel it is easier to understand 'const char *item1 = *((const char **)
>> a);' than 'const char *item1 = *((const char * const *) a);'.
>>
>
> This patch changes the semantics of those statements.
>
Agreed. Can someone point me to the docs where I can understand the
typecasting of the above nature?
With regards
Kamesh Jayachandran
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH]simple(for me only? not sure) typecasting
Posted by Daniel Rall <dl...@collab.net>.
On Thu, 12 Oct 2006, Kamesh Jayachandran wrote:
> Hi All,
> I found the following snippet in subversion/libsvn_subr/sorts.c.
>
> <snip>
> svn_sort_compare_paths(const void *a, const void *b)
> {
> const char *item1 = *((const char * const *) a);
> const char *item2 = *((const char * const *) b);
> return svn_path_compare_paths(item1, item2);
> }
> </snip>
> I feel it is easier to understand 'const char *item1 = *((const char **)
> a);' than 'const char *item1 = *((const char * const *) a);'.
This patch changes the semantics of those statements.