[cfe-dev] Pointers to Overloaded C Functions

George King gwk.lists at gmail.com
Mon Jan 4 09:53:21 PST 2010

I am experimenting with clang's overloaded C functions, and I can't figure out how to get a pointer to an overloaded function. 

test program:

#define OL __attribute__((overloadable))

void OL a(int x) { printf("i: %d\n", x); }
void OL a(float x) { printf("f: %f\n", x); }

int main(int argc, char** argv)
    void(*a_i_ptr)(int) = a;
    void(*a_f_ptr)(float) = a;
    return 0;

compiler output:

> clang test_ol.c 
test_ol.c:25:11: error: incompatible type initializing '<overloaded function type>', expected
      'void (*)(int)'
    void(*a_i_ptr)(int) = a;
          ^               ~
test_ol.c:26:11: error: incompatible type initializing '<overloaded function type>', expected
      'void (*)(float)'
    void(*a_f_ptr)(float) = a;
          ^                 ~
2 diagnostics generated.

If I change the name of one of the functions, then it compiles; clang appears well aware of the syntactic ambiguity. Is there a more specific syntax to specify which function I'm  referring to?

Something like "void(*a_i_ptr)(int) = a(int);" makes sense to me, but I imagine that it's a stretch as far as extending the language goes. 



More information about the cfe-dev mailing list