samuel ammonius wrote:
> In the qtc project I linked to earlier, I managed to implement function
> overloading in C using vardiac macro functions that would find the number
> of parameters and add that number to the end of the function. For example,
> QPushButton() would become QPushButton0(), and
> QPushButton(QString("hello")) would become QPushButton1(QString("hello")).
> For overloaded functions with the same amount of parameters, I used the
> _Generic keyword to find the right function using the parameter's type.
> Here <https://github.com/sammonius/qtc/blob/main/header/qpushbutton.h>'s
> one example (QPushButton_new(), lines 12-21).

Be warned that using variadic macros and _Generic means your code requires 
at least C11, if not compiler-specific extensions. (Variadic macros are C99 
or compiler-specific depending on the exact syntax you use, _Generic is C11, 
availability when selecting an older C standard is compiler-dependent.) This 
requirement ought to be documented in README.md.

        Kevin Kofler

_______________________________________________
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development

Reply via email to