keyboard/mouse programming



 DEVELOP > c-Plus-Plus > keyboard/mouse programming

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1
Topic: DEVELOP > c-Plus-Plus
User: "J de Boyne Pollard"
Date: 07 Dec 2007 06:29:14 AM
Object: keyboard/mouse programming
s> int *f(int x)
s> {
s> return(&x); /* this address points to storage local of f() */
s> }
s>
s> such a returned pointer is ... invalid,
RP> False, not in agreement. The pointer is valid. A pointer
RP> can point to anything. The value from the derefenced
RP> pointer is invalid.
RP> [...] it can be returned and assigned to another pointer
RP> without being dereferenced...
Incorrect. There exist implementations (e.g. x86 architecture when
using far or huge data memory models and the AS/400) where
deallocation of storage causes the _values_ of any pointers to that
storage to become invalid. (Loading the value of the pointer into a
CPU pointer register causes a processor fault.) So simply using the
_values_ of the pointers, without even dereferencing them, causes
undefined behaviour. The C++ standard mentions this in regard to
storage with dynamic storage duration. The C standard is more general
and points out that the values of pointers to an object become
indeterminate after that object's lifetime, irrespective of storage
duration, ends.
.

 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER