[Development] Could support for C be added to Qt?

Kevin Kofler kevin.kofler at chello.at
Sun Sep 11 16:35:59 CEST 2022

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

More information about the Development mailing list