class object initialisation

T

tom_usenet

Not even as void?

This is illegal, even though it isn't dereferenced:

void* p = ::eek:perator new(1);
::eek:perator delete(p);
void* q = p; // boom

You aren't allowed to convert a pointer to an rvalue after deleting
it. You can of course reassign it:
p = 0; //or whatever.

Tom
 
A

Attila Feher

tom_usenet said:
This is illegal, even though it isn't dereferenced:

void* p = ::eek:perator new(1);
void* q = p; // boom

You aren't allowed to convert a pointer to an rvalue after deleting
it. You can of course reassign it:
p = 0; //or whatever.

Ahha. Makes sense, but quite restrictive. So basically you will need to
store it as "whatever", but not as a pointer if you want to keep the value
around.
 
A

Alexander Terekhov

Attila Feher wrote:
[...]
Ahha. Makes sense, but quite restrictive. So basically you will need to
store it as "whatever", but not as a pointer if you want to keep the value
around.

Even if you store it BEFORE free-ing... since the representation
may have quite a few garbage bits, storing it as "whatever" will
be nothing but "absolutely pointless exercise"... well, just a
few exceptions (I have a patent appl on one of those ;-) ) aside,
of course.

regards,
alexander.
 
A

Attila Feher

Alexander said:
Attila Feher wrote:
[...]
Ahha. Makes sense, but quite restrictive. So basically you will
need to store it as "whatever", but not as a pointer if you want to
keep the value around.

Even if you store it BEFORE free-ing... since the representation
may have quite a few garbage bits, storing it as "whatever" will
be nothing but "absolutely pointless exercise"... well, just a
few exceptions (I have a patent appl on one of those ;-) ) aside,
of course.

Since looking at them later is a "platform dependent exercise" I believe
that whatever garbage bits they have it does not really matter at all.

class DeadPtr {
unsigned char bitz[sizeof(void*)]; // Could be char *
public:
DeadPtr( void const* p) { memcpy and so on}
DeadPtr( void const* const p) { memcpy and so on}
// Something special/platform dependent to display it
};

Off course ;-) this thingy has to be made _before_ the delete is being
called. I dunno if passing as reference counts as use as rvalue... if not
that can be done.
 
W

White Wolf

Gary Labowitz wrote:
[SNIP]
Well, I like your obfuscation! I didn't understand anything! It's
ready for publication!
On the serious side, the fact that there are invalid combinations of
bits for types introduces a whole new complexity for me, and makes
the standard almost unbearably complex. Oh well, reality must be
faced.
On the whole, I rather prefer Java: nine simple types to learn about,
all well defined with regard to bit usage and size, no surprises.

Nine types? No surprises? I dunno, but whenever I had to try to find
something in the Java libraries (find+understand) I finally gave up. It is
like having to talk to all Chineese and Indian people to find a street
address. Messy.

Anyways. C++ is a general purpose programming language with systems
programming in mind. Comparing it to Java is like comparing apples to the
moon.
 
W

White Wolf

Gary said:
Thank you. If this be the case, then all my musings are incorrect.
Hmm... check sum bits in a value. Yes, it could. Then invalid bit
combinations could exist. All resulting in undefined behavior I
should think.

Yep. In fact of life it is quite unusual for the "common people" to find a
HW which works like this. Anyways using a garbage value is not a really
good thing to do, even if one can get away with it without a crash.
Back to the drawing board!!!
[Gee, what did we go back to before they invented drawing boards?]

Me go bangbang wife. :) Or maybe: back to the cave wall. :)
 

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
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top