How to achieve function overloading in C?

前端 未结 14 2626
清歌不尽
清歌不尽 2020-11-22 03:16

Is there any way to achieve function overloading in C? I am looking at simple functions to be overloaded like

foo (int a)  
foo (char b)  
foo (float c , i         


        
14条回答
  •  梦谈多话
    2020-11-22 04:15

    This may not help at all, but if you're using clang you can use the overloadable attribute - This works even when compiling as C

    http://clang.llvm.org/docs/AttributeReference.html#overloadable

    Header

    extern void DecodeImageNow(CGImageRef image, CGContextRef usingContext) __attribute__((overloadable));
    extern void DecodeImageNow(CGImageRef image) __attribute__((overloadable));
    

    Implementation

    void __attribute__((overloadable)) DecodeImageNow(CGImageRef image, CGContextRef usingContext { ... }
    void __attribute__((overloadable)) DecodeImageNow(CGImageRef image) { ... }
    

提交回复
热议问题