Am 21.09.2016 um 12:00 schrieb Marc Mutz:
On Wednesday 21 September 2016 11:42:41 Mathias Hasselmann wrote:
No matter what order I use for config and value, the compiler will pad
and -Wpadded will complain. How am I supposed to fix this? This
solutions that come to my mind all are ugly, but most likely I am just
stupid.

Tabs? Seriously? :)

E-mail clients and their horrible text editors.


        struct Sensor
        {
            enum Config { NotInitialized, PullUp, PullDown, Analog };

            Config config;
            char padding[alignof(QVariant) - sizeof(Config)];
            QVariant value; //[1]
        }

and pray for alignof(QVariant) - sizeof(Config) != 0.

Yup, one of solutions I had in mind and rejected for expected that prayer remaining unheard while juggling with 32 and 64 bit code.

I wasn't serious about -Wpadded, but incidentally, my example shows that type
traits also won't help. We have a handful of classes in Qt which have a
'reserved' field that doesn't get initialized (so it better should be named
'unusable'). A type trait cannot tell if a field called 'padding', 'reserved',
'unused' or 'unusable' is meant to be part of equality or not.

Q_DECLARE_TYPEINFO(QBar, Q_PADDED_TYPE) // :D

Ciao,
Mathias
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to