[SciPy-Dev] bool wrapper in sparse
Sun Jun 30 09:37:07 CDT 2013
On 30 Jun 2013 15:14, "Charles R Harris" <email@example.com> wrote:
> 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
>> > > 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
>> > 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.
Not only is that a terrible idea, it is (these days) actually a violation
of the standard. But the standard does allow padding *after* the sole
element in a single-element struct.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-Dev