www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22884] New: ImportC: error when casting between function


          Issue ID: 22884
           Summary: ImportC: error when casting between function pointers
                    for statically initialized variables
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ImportC, rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dave287091 gmail.com

The following C code fails to compile. This kind of pointer cast can be seen in
sqlite and also in some C library APIs like python.

int printf(const char*, ...);
typedef void (*funcptr)(void);

funcptr a = printf; // ok
funcptr b = (funcptr)printf; // Error: non-constant expression `printf`

funcptr foo(void){
    funcptr f = (funcptr)printf; // ok
    return f;

Mar 17 2022