[Development] On the use of the inline keyword

Ahmad Samir a.samirh78 at gmail.com
Fri Aug 25 14:20:18 CEST 2023


On 25/8/23 14:11, Cristian Adam via Development wrote:
> The other way of fixing this is by using ... macros. The article at c++ - Importing inline functions in MinGW - Stack Overflow<https://stackoverflow.com/questions/11546403/importing-inline-functions-in-mingw>  mentions using inline in the class declaration.
> 
> Their example works fine with both GCC MinGW and Clang MinGW. Visual C++ is also fine:
> 
> #ifdef _WIN32
> #define Q_EXPORT_INLINE inline
> #else
> #define Q_EXPORT_INLINE
> #endif
> 
> 
> class __declspec(dllimport) MyClass {
> public:
>      Q_EXPORT_INLINE int myFunc2();
>      Q_EXPORT_INLINE int myFunc1();
> };
> 
> inline int MyClass::myFunc2(void) {
>      return myFunc1();
> }
> 
> inline int MyClass::myFunc1(void) {
>      return 0;
> }
> 

[...]

The main deterrent to not fix it like the qstring.h patch[1] is the churn caused 
by changing many lines, in many files, right?

But if affected code is going to be changed anyway to fix it with macros, it makes 
more sense to fix it like [1]; if you're changing those lines, may as well adhere 
to more standard guidelines: inline keyword is only used on function declaration 
and _not_ the definition.


My 2p's.

[1] https://codereview.qt-project.org/c/qt/qtbase/+/498739


Regards,
Ahmad Samir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/development/attachments/20230825/bb4d8a81/attachment.sig>


More information about the Development mailing list