← Back to team overview

kicad-developers team mailing list archive

Re: Damned the 'undefined global constructor order'

 

On 06/10/2014 01:49 PM, Dick Hollenbeck wrote:
> On 06/10/2014 11:31 AM, Lorenzo Marcantonio wrote:
>> On Tue, Jun 10, 2014 at 10:04:36AM -0500, Dick Hollenbeck wrote:
>>> 1) mask: uint64_t
>>> 2) index (LAYER_NUM) enum, interchangeable with int in some contexts.
>>
>> An enum IIRC is always implicitly convertable to an int.
>>
>> These rules are really nasty, I'll need to try if it accept them. And
>> anyway I'd wanted to avoid mask literals to avoid problems of any kind.
> 
> 
> If you back out of your operator | ( LAYER_NUM ), and only use this operator with the
> masks, then we might envision a migration path to YOUR objective.  The objective is "get
> rid of the layer masks".  I'm saying we can do it over time.

Lorenzo,

Please bear with me, while we're still brainstorming.

Looking at class bitset in detail, they already have all the operator overloads you'd ever
need, so long as you only use a std::bitset on both sides of the operator.

So if we keep it simple, I think the masks can go now in favor of pre-built single bit LSETs.

Have you tried putting all the static constructors in one file?  I had the idea that they
would be constructed in order of appearance then.

Start by defining each layer individually, and build up from there, always building
another std::bitset in constructors.

Forget any new operators, I don't see where need them.

See attached file which seems to work fine.  Compile it and run it please.

$ gcc -o test test.cpp




#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   LSET_CU_FRONT;
    static const LSET   LSET_CU_BACK;
    static const LSET   LSET_CU_EXTERNAL;

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

    // this should not be inline.
    LSET( uint64_t aSet )
    {
        for( unsigned i=0;  aSet;  ++i, aSet >>= 1 )
        {
            if( aSet & 1 )
                set( i );
        }
    }

    /*
    LSET& set( size_t index )
    {
        return (LSET&) BASE_SET::set( index );
    }
    */
};


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

const LSET LSET::LSET_CU_FRONT( LMSK( LAYER_CU_FRONT ) );
const LSET LSET::LSET_CU_BACK( LMSK( LAYER_CU_BACK ) );
const LSET LSET::LSET_CU_EXTERNAL = LSET_CU_FRONT | LSET_CU_BACK;


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

    return 0;
}


Follow ups

References