Re: how to release memory?



On Mon, 30 Jun 2008 07:30:28 -0700 (PDT), vippstar@xxxxxxxxx wrote:

On Jun 30, 5:40 am, Keith Thompson <ks...@xxxxxxx> wrote:
Barry Schwarz <schwa...@xxxxxxxx> writes:
On Sun, 29 Jun 2008 16:29:39 -0400, pete <pfil...@xxxxxxxxxxxxxx>
wrote:

snip

It's case 4, from Clive's other quoted statement,
which came out more messy than I remember sending it
(I miss my old newsreader):

We've lost the part you refer to but I believe the only thing of
interest is that a pointer p is indeterminate.

[cases 1..3 snipped]

(4) value is ignored, such as "(void) p" or "sizeof p".
[...]
Case 4 represents two different situations:

(void)p still causes p to be evaluated, even if the result of the
evaluation is discarded. This invokes undefined behavior. I'm not
sure but I expect that if the compiler optimizes the statement away
**completely**, then the undefined behavior caused by the evaluation
also disappears.

Right, except that the compiler is free to optimize the statement away
completely and replace it with code to cause demons to fly out of your
nose.

More reasonably, a compiler that generates extra run-time checks might
replace the evaluation of ``(void) p'' with code to cause a deliberate
run-time trap.

Is '(void)expr;' really invoking undefined behavior if expr's value
cannot be inspected?
What about 'expr;' without the cast?

This cast did not contribute anything to the issue. The undefined
behavior is caused by evaluating the indeterminate value.

A question perhaps not that related, are any of these two marked lines
valid:

...
void *p = NULL;
*p; //
(void)*p; //

Both are coding errors that *should* require a diagnostic. While the
standard doesn't ever say you cannot dereference a void*, it does say
that dereferencing a pointer to object type T results in an lvalue
designating the object and the lvalue has type T. Neither an lvalue
nor an object can have type void (it is an incomplete type that cannot
be completed).

If the compiler chooses to accept the source and produce an
executable, undefined behavior will occur when either statement is
executed as described in footnote 87.
...

gcc warns about 'dereferencing void * pointer', however it's a warning
and not an error.


Remove del for email
.



Relevant Pages

  • Re: is there a way to do this...
    ... >>void change ... i is a pointer to int, and on this platform, consumes a place in a ... This defines ptr to be a pointer to characters, ... the compiler intended us to go. ...
    (comp.lang.c)
  • Re: Determining a functions calling address
    ... >> conversion between pointer to any type of function and pointer to ... >> void, or indeed pointer to any other object type. ... Apparently you are not using a real C++ compiler, ... First you should have received diagnostics along these lines: ...
    (comp.lang.cpp)
  • Re: Few questinos
    ... ANSI C says you are allowed to use sizeof. ... Does this work for void type? ... but it won't set the corresponding pointer in the calling ... "Undefined behavior" includes the possibility that the implementation ...
    (comp.lang.c)
  • Re: gcc knows about malloc()
    ... and may prevent the compiler from ... void *malloc; ... different effect than a different piece of C syntax in a declaration. ... and converting the bogus pointer to a pointer to function ...
    (comp.lang.c)
  • Re: Few questinos
    ... ANSI C says you are allowed to use sizeof. ... Does this work for void type? ... but it won't set the corresponding pointer in the calling ... "Undefined behavior" includes the possibility that the implementation ...
    (comp.lang.c)