Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-08-24 21:57:30

On Thu, Aug 24, 2000 at 11:52:10AM -0500, Bill Wade wrote:
> > It seems to me that ((const char**)symbols)[2] has to work, in
> > any case. The
> > reasoning? The compiler is not allowed to perform bounds checking on a raw
> > pointer, and the expression above creates a temporary raw pointer before
> > indexing it. Am I missing something?
> The compiler is allowed to perform bounds checking on a raw pointer.

The compiler is allowed to do anything it wants... but I not sure
about the definition of the notion of the array pointed to by a

I would just say that the standard is so vague that you can anything
that pleases you.

> I
> don't think you can find anything in the standard that guarantees
> void* x = new char[10];
> (char*)x+20;
> has defined behavior.

It is clear that this one as undefined behaviour (except with a
replaced operator new).

> On the other hand, for the struct hack the math on
> the raw_pointer stays within a contiguous block of memory that you have
> allocated. I think that means that you should be ok. However the standard,
> in general, takes a dim view of casting a pointer between unrelated types.

Indeed (and it's a bad idea in general).

> Almost all implementations are much more forgiving than the standard.
> int i;
> assert(&i == (void*)(short*)(void*)&i);
> I've never used an implementation that would trip the assert, but the
> standard allows this to fail, and it probably invokes undefined behavior.

This one has a well defined behaviour, and the assert shall pass.

Valentin Bonnard

Boost list run by bdawes at, gregod at, cpdaniel at, john at