[SciPy-Dev] bool wrapper in sparse
Charles R Harris
Sun Jun 30 09:14:48 CDT 2013
On Thu, Jun 27, 2013 at 4:19 PM, Nathaniel Smith <firstname.lastname@example.org> wrote:
> On 27 Jun 2013 22:56, "Pauli Virtanen" <email@example.com> wrote:
> > 27.06.2013 00:22, Blake Griffith kirjoitti:
> > > So basically I define a class that behaves like bool, but add compiler
> > > specific parameters to make instance of this class 1 byte?
> > Pretty much so, for known compilers (gcc, msvc).
> > I'd also put an assertion somewhere in the code. Either inside one of
> > the functions, or try to construct a compile-time assertion via some
> > trickery. C++11 has static_assert that would do the job, but that's a
> > bit too new standard to rely on. However, there are some tricks to do it
> > in any case (check stackoverflow for "sizeof compile time assert").
> Also it's unlikely that any trickery will be needed on any real world
> compiler. Standard c++ guarantees you can cast between npy_bool* and
> npy_bool_wrapper*; the only concern is that arrays might not have the same
> memory layout. And I don't think any compiler will add padding to a 1 byte
> struct. chars don't need word alignment! (But of course I could be wrong.)
IIRC, in ancient times, the Borland compiler added an identifying number as
the first entry in all classes. Needless to say, that played hob with
classes like complex. That innovation didn't last long.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-Dev