keyboard/mouse programming

Discussion in 'C++' started by J de Boyne Pollard, Dec 7, 2007.

  1. 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.
    J de Boyne Pollard, Dec 7, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bas Mekel

    Unable to use mouse or keyboard

    Bas Mekel, Oct 15, 2003, in forum: Java
    Replies:
    0
    Views:
    332
    Bas Mekel
    Oct 15, 2003
  2. Replies:
    0
    Views:
    345
  3. Replies:
    2
    Views:
    496
    Thomas Fritsch
    Feb 7, 2005
  4. Peter

    keyboard, mouse and Win98

    Peter, Jul 25, 2003, in forum: C++
    Replies:
    0
    Views:
    321
    Peter
    Jul 25, 2003
  5. J de Boyne Pollard

    keyboard/mouse programming

    J de Boyne Pollard, Dec 7, 2007, in forum: C Programming
    Replies:
    1
    Views:
    282
    Mark Bluemel
    Dec 7, 2007
Loading...

Share This Page