03-12-2015 04:43 PM
Hello,
The LabWindows/CVI 2013 help page for C Language Extensions appears to show function overloading being supported in the C99 extensions:
"Function Overloading in C | Yes"
The table in the following link shows the same thing:
http://digital.ni.com/public.nsf/allkb/73AEAD30C8AF681A86257BBB0054A26B
I tried compiling a source file with the following overloaded function definitions with C99 extensions enabled in the Build Options:
void myFunctionOne(double d) {
printf ("Value = %f\n", d);
}
void myFunctionOne(int d) {
printf ("Value = %d\n", d);
}
and I get the error:
"conflicting types for 'myFunctionOne'
Is function overloading truly supported, and if so, how does one enable it?
Thanks,
Mark B.
Solved! Go to Solution.
03-13-2015 03:11 AM - edited 03-13-2015 03:25 AM
Oh, I was a bit too quick, Constantin has the better answer
03-13-2015 03:20 AM
Hello Mark,
You have to add __attribute__((overloadable)) at the definitions of the functions you want to overload.
void __attribute__((overloadable)) myFunctionOne(double d) { printf ("Value = %f\n", d); } void __attribute__((overloadable)) myFunctionOne(int d) { printf ("Value = %d\n", d); }
You can see an examples of clang extensions here.
Constantin
03-13-2015 09:15 AM
Thanks, Constantin. Works perfectly. Looks like there's a whole world of attributes out there - I see a research project in my future.
Wolfgang, thanks for taking the time to reply, also.
Best regards,
Mark B.
03-16-2015 10:29 AM
I think you can also use the 'weak' attribute and/or pragma, although I haven't tried.
03-16-2015 10:39 AM
@gdargaud wrote:
I think you can also use the 'weak' attribute and/or pragma, although I haven't tried.
Thanks, I'll look into it.
Mark