In <pgcpe0pelmp2j7htk3oo6todqj9icsbecr@4ax.com> Jack Klein <jackklein@spamcop.net> writes:
[color=blue]
>On 7 Jul 2004 13:09:02 GMT,
Dan.Pop@cern.ch (Dan Pop) wrote in
>comp.lang.c:
>[color=green]
>> In <ccfd8i$8l$1@news.apple.com> Peter Ammon <peter_ammon@rocketmail.com> writes:
>>[color=darkred]
>> >Often times, I'll have some malloc()'d data in a struct that need not
>> >change throughout the lifetime of the instance of the struct.
>> >Therefore, the field within the struct is declared a pointer to const
>> >[something]. But then free() complains when I pass in the pointer
>> >because free() is declared as void free(void*). So I have to cast.[/color]
>>
>> Welcome to the world of const poisoning. Don't use const and your
>> troubles are gone.
>>[color=darkred]
>> >Why is it not declared as void free(const void*), which would save me
>> >these headaches?[/color]
>>
>> Because it would be semantically incorrect: this declaration promises
>> you that free() won't modify the data pointed to by its parameter. Or
>> the free() function is specified as *destroying* this data.[/color]
>
>No, it is defined to do no such thing.
>
><quote>
>7.20.3.2 The free function
>
>Synopsis
>
>1 #include <stdlib.h>
> void free(void *ptr);
>
>Description
>
>2 The free function causes the space pointed to by ptr to be
>deallocated, that is, made available for further allocation. If ptr is
>a null pointer, no action occurs. Otherwise, if the argument does not
>match a pointer earlier returned by the calloc, malloc, or realloc
>function, or if the space has been deallocated by a call to free or
>realloc, the behavior is undefined.
>
>Returns
>
>3 The free function returns no value.
><end quote>
>
>Not one single word about destroying the data, or indeed any
>specification at all about what happens to the contents of the memory.
>In point of fact, a strictly conforming program cannot determine
>whether the contents of the memory is modified in any way or not.[/color]
Learn to read, Jack, learn to read. If a block is deallocated, what
happens to the data it contained before deallocation? It becomes
irreversibly inaccessible, so *for all intents and purposes* it is
destroyed. No one cares whether it was actually touched by the execution
of free(), this is immaterial.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email:
Dan.Pop@ifh.de