[Issue 24414] ImportC: undefined identifier `__builtin_clz`
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon Feb 26 16:09:32 UTC 2024
    
    
  
https://issues.dlang.org/show_bug.cgi?id=24414
Alex Bryan <abryanbugzilla at proton.me> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |abryanbugzilla at proton.me
--- Comment #1 from Alex Bryan <abryanbugzilla at proton.me> ---
I've ran into this issue before and worked around it by putting this in a D
file:
module util;
// for C files built with import C that try to use GCC/clang builtin that
importC does not provide
extern(C) int __builtin_clz(int v)    
{    
    return clz(v);    
}    
// count leading zeros.    
int clz(uint v) pure nothrow @nogc @safe    
in(v != 0)    
{    
    import core.bitop : bsr;    
    return 31 - bsr(v);    
}
and putting
__import util
at the top of the C file
--
    
    
More information about the Digitalmars-d-bugs
mailing list