Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > keyboard/mouse programming

Reply
Thread Tools

keyboard/mouse programming

 
 
J de Boyne Pollard
Guest
Posts: n/a
 
      12-07-2007
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C (functional programming) VS C++ (object oriented programming) Joe Mayo C Programming 168 10-22-2007 01:00 AM
Can Your Programming Language Do This? Joel on functional programming and briefly on anonymous functions! Casey Hawthorne Python 4 08-04-2006 05:23 AM
Wireless PEAP/MSCHAPV2 client programming question Jim Howard Wireless Networking 6 07-02-2005 11:53 AM
systems programming versus application programming Matt Java 35 07-22-2004 08:10 AM
XSLT programming cameron Firefox 0 01-04-2004 10:51 PM



Advertisments