[SciPy-Dev] bool wrapper in sparse
Thu Jun 27 17:19:34 CDT 2013
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.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-Dev