LNK2019 error from using a function pointer to core.bitop functions?

Roland Hadinger via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 17 08:47:37 PDT 2015


On Thursday, 16 July 2015 at 03:24:54 UTC, Matthew Gamble wrote:
> This member function of my struct uses a function pointer btx. 
> When the line declaring the function pointer is present I get a 
> LNK2019 error: unresolved external symbol.

Just guessing, probably because bts and btr are intrinsics?

If performance is not that important, you can always do this at 
the start of your opIndexAssign method:

     static int bts(size_t* p, size_t bitnum) { return .bts(p, 
bitnum); }
     static int btr(size_t* p, size_t bitnum) { return .btr(p, 
bitnum); }
     int function(size_t*, size_t) btx = (value) ? &bts : &btr;

Otherwise, I'd use templates and an alias. Maybe this will result 
in faster code:

     bool opIndexAssign(bool value, size_t[2] inds)
     {
         void impl(bool b)(size_t[2] inds)
         {
             static if(b)
                 alias btx = bts;
             else
                 alias btx = btr;

             // code from opIndexAssign goes here...
             // for (size_t i = startBitInd; ...
         }

         if( value )
             impl!true(inds);
         else
             impl!false(inds);
     }



More information about the Digitalmars-d-learn mailing list