← Back to team overview

kicad-developers team mailing list archive

Re: Damned the 'undefined global constructor order'

 

boiled down a bit more, attached.

#include <stdio.h>
#include <stdint.h>

//#define __STDC_FORMAT_MACROS

#include <inttypes.h>
#include <vector>


#include <bitset>

enum LAYER_NUM
{
    LAYER_CU_FRONT,
    LAYER_CU_1,
    LAYER_CU_2,
    LAYER_CU_BACK,
};


typedef std::bitset<64> BASE_SET;

class LSET : public BASE_SET
{
public:
    static const LSET   CU_FRONT;
    static const LSET   CU_BACK;
    static const LSET   CU_EXTERNAL;

    LSET( const BASE_SET& aOther ) :
        BASE_SET( aOther )
    {
    }

    LSET( uint64_t aBitMask );
};


//--- above into a header, below into a *.cpp ------------------------

LSET::LSET( uint64_t aSet )
{
    for( unsigned i=0;  aSet;  ++i, aSet >>= 1 )
    {
        if( aSet & 1 )
            set( i );
    }
}


// defined locally, not in header:
#define LMSK( x )   (uint64_t(1) << (x))

const LSET LSET::CU_FRONT( LMSK( LAYER_CU_FRONT ) );
const LSET LSET::CU_BACK( LMSK( LAYER_CU_BACK ) );

const LSET LSET::CU_EXTERNAL = CU_FRONT | CU_BACK;


int main( int argc, char** argv )
{
    // probably endian specific, but for testing is fine.
    printf( "value %08" PRIx64 "\n", *(int64_t*) &LSET::CU_EXTERNAL );

    return 0;
}


Follow ups

References