Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-08-07 18:56:09


> > [...]
> > get_type_id() gets the s_id associated with the target; it's a distinct
> > number in the range of [0, no of pointed classes]. It is transformed
> > into an index for lookups.
>
> Isn't it true that get_type_id() make assumptions about the binary layout
> of the class? That is undefined, let alone non-portable.

Is it a compile-time defined token, not a binary dependency.

> > [...]
> > Up to now I've just tested ptr.h with pointer.cpp; only one source file.
> I
> > think gcc is duplicating templates & static members everywhere but
> > can be prevented with #pragma interface macros.
>
> Is that portable?

No, but it will still work if static variables are duplicated anyway.
Lookup tables will be smaller at the same time since classes taken cared of
will be divided and specific to each source file.

> > [...]
> > Let's not forget that (int *) 0 + sizeof(double) will be equal to 0x20
> since
> > the addition multiplies sizeof(int) sizeof(double) times. It is so much
> > easier with offsets.
>
> I see that you might have the desired semantics with int* arithmetic, but
> you convert to char* anyway, so why not use sizeof() directly with char*?

Why not? It is less error-prone.

> > [...]
> > If I use resize() instead, will it shrink down the allocated block
> (exactly
> > what I don't want) if the new size is smaller than the previous one?
>
> Yes, it will. Which is why the correct solution is to put a check to see
if
> the new size is larger than the existing size, push_back until it is the
> right size. And yes, that is probably just as expensive as it sounds.

I will insert n null values using resize() using an if condition simply.

> > [...]
> > ptrdiff_t is a macro, is therefore not flexible. offset was created to
> > simplify pointer arithmetics and to remove some implicit headaches...
> > [...]
>
> How is ptrdiff_t being a macro "not flexible"? It should be defined as
> the difference type for pointer arithmetic on any given platform, which
> is what offset does.

ptrdiff_t will be transformed into an integer and operator + () will
overload every integer additions, etc. IMO the code is cleaner this way and
(char *) arithmetics is portable.

Philippe A. Bouchard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk