[Development] Meaning of Q_PRIMITIVE_TYPE?
Thiago Macieira
thiago.macieira at intel.com
Tue Apr 3 14:29:44 CEST 2012
On terça-feira, 3 de abril de 2012 10.20.11, Marc Mutz wrote:
> Hi,
>
> On Tuesday April 3 2012, jedrzej.nowacki at nokia.com wrote:
> [...]
>
> > > Also, QVarLengthArray should zero-initialise, but it doesn't.
> >
> > I like this feature it allows to avoid double initialization in some
> > cases,
> > but maybe it is not the most intuitive behavior. Anyway it is a bit out of
> > scope.
>
> If you want to avoid double initialisation, the correct way is
> reserve()+push_back(), not resize()+operator[]. That works even for complex
> types.
The thing is that, like Lars said, QVarLengthArray was invented to replace the
C99 feature of variable-length arrays, hence the name. In C99 but not in C++98
or C++11, you can write:
char buffer[length];
where length is not a constant expression (to borrow a C++11 term). That buffer
is not initialised because char has no constructor.
So like Jędrzej says, the users expect that an array of chars is uninitialised
to garbage, but an array of QUuid is properly zeroed because this produces a
zero QUuid:
QUuid uuid;
My experience producing a type that doesn't initialise by default
(QElapsedTimer) is that users really don't expect C++ types to remain
uninitialised.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Intel Sweden AB - Registration Number: 556189-6027
Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120403/e5878676/attachment.sig>
More information about the Development
mailing list