keyboard/mouse programming

  • Thread starter J de Boyne Pollard
  • Start date
J

J de Boyne Pollard

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top