tags:

views:

40

answers:

1

can somebody please explain what does it mean : passing arg 1 of 'free' discards qualifiers from pointer target type thanks in advance

A: 

I believe "discards qualifies" pertains to const or volatile. So you're probably passing a const pointer as a non-const argument.

You code probably resembles the following:

#include <stdlib.h>
int main() {
    const double *x ;
    x = (double *) malloc(4 * sizeof(double)) ;
    free(x) ;
    return 0 ;
}

I borrowed this example from a similar question asked on an online forum.

The problem is that since you've said the data you're point to is const, you can't change it. You can't initialize it, you can't modify it, you can't free it. So don't use a const pointer as your only pointer to the result of a malloc.

Fred Larson
yes, You are right, I'm passing it to free, why do I receive warning, what can I do with this?
lego69
You probably don't want to use `const` on a pointer you're using with `malloc` and `free`. For what it's worth, I found a discussion on this topic: http://www.phwinfo.com/forum/comp-lang-c/299780-free-consted-memory-without-warning.html
Fred Larson