Re: Why is the kfree() argument const?



Hi,

Christoph Lameter <clameter@xxxxxxx> writes:

On Wed, 16 Jan 2008, Johannes Weiner wrote:

So if I got it right and you actually modify the memory you only got a
const pointer to, you reach a level where you _have to_ break this
policy and cast to a non-const pointer, as it is currently done in
kfree(). No?

Correct and we have gcc 4.2 currently spitting out warnings because of
casting to non const. Any idea how to convince gcc that this is okay?

Just for the record, this really seems to be a gcc bug, I can not
explain this otherwise:

$ cat test.c
#include <stdio.h>

static void test(void *p)
{
char *v = p;
puts(v);
}

int main(void)
{
const char foo[] = "foo";
test((void *)foo);
return 0;
}
$ gcc -Wall test.c -o test
$ gcc -Wall -O test.c -o test
test.c: In function 'main':
test.c:12: warning: passing argument 1 of 'test' discards qualifiers from pointer target type
$ gcc -Wall -O -fno-inline test.c -o test
$

gcc is version 4.2.2.

Hannes
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: [CRED bug?] 2.6.29-rc3 dont survive on stress workload
    ... qualifiers from pointer target type ... It fails to observe the ... fact that a const pointer is cast to the equivalent non-const pointer in ... If by 'some versions of gcc' you mean 'gcc 4.2.2' then yes. ...
    (Linux-Kernel)
  • Problems by configure / make on squidguard 1.2.0
    ... checking for gcc... ... checking whether the C compiler works... ... checking whether yytext is a pointer... ... netkit-bootparamd 0.17-1 ...
    (comp.os.linux.setup)
  • Problems by configure / make on squidguard 1.2.0
    ... checking for gcc... ... checking whether the C compiler works... ... checking whether yytext is a pointer... ... netkit-bootparamd 0.17-1 ...
    (comp.os.linux.security)
  • nessus libnasl compile error.
    ... checking for gcc... ... checking struct ip contains ip_csum... ... nasl_text_utils.c:1177: warning: assignment makes pointer from integer ... incompatible pointer type ...
    (comp.os.linux.security)
  • Re: the printk problem
    ... The thing is that GCC checks types. ... pointer specially", but you can't in general add new printf arguments ... add new printf control chars and maybe even tell gcc how to check them. ... struct inode *inode; ...
    (Linux-Kernel)

Loading