Ethereal

Re: [Ethereal-dev] Help with "different 'const' qualifiers", "pointer mismatch for a ctual parameter
Google
 
Web Ethereal.com

Home | Introduction | Documentation | Lists | FAQ | Development | Wiki | Bugs

Ethereal-dev: February 2005


Francisco Alcoba (TS/EEM) wrote:

So, if I have

	address tmp_src, tmp_dst;
	guint32 ipv4_address;

and do
      g_free(tmp_src.data);
or
	g_memmove(tmp_src.data,&ipv4_address,4);

I get both warnings in a row. I do not have them if I do

 	g_free((void *)tmp_src.data)

but I'm not sure this is OK -meaning, it will do what I need without breaking anything
else-.

That's the best you can do when freeing data, as far as I know; it's what we do elsewhere.


The underlying problem is that there is, as far as I know, no good way in C to indicate that some piece of data is immutable, i.e. once it's been initialized its value can't be changed, but can be freed, so I think all you can do is throw in a cast to indicate that it's OK to free the data.

For initializing the data, I'd do

	guint32 *src_data;

	src_data = g_malloc(sizeof *src_data);
	*src_data = ipv4_address;
	tmp_src.data = &src_data;

I've found a reference to a similar situation, that claims this to be some sort of VC6-specific behaviour,

The claim isn't true - the idea of warning about a const pointer being passed to a routine where the matching argument isn't VC6-specific, only the text of the message is:


	$ cat foo.c
	#include <stdlib.h>

void
freeit(const char *p)
{
free(p);
}
$ gcc -c -O2 -Wall -W foo.c
foo.c: In function `freeit':
foo.c:6: warning: passing arg 1 of `free' discards qualifiers from pointer target type



Powered by MHonArc 2.6.10