Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: strange error (QT Creator 4.12.2, based on QT creator 5.14.2) Date: Fri, 03 Mar 2023 09:29:46 -0800 Organization: None to speak of Lines: 39 Message-ID: <87edq5n3p1.fsf@nosuchdomain.example.com> References: <87ilfimysr.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="faddc2c373036d68cc5ec870139a1e06"; logging-data="734161"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19G1AW6sg6fC/pgqHbnaATX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:di2bvbS1KRWoQq0Y6EVR898Y84Q= sha1:fZor0eX5tXgs17wDex9oqDlV9r0= Xref: csiph.com comp.lang.c++:89411 MarioCPPP writes: > On 03/03/23 02:03, Keith Thompson wrote: >> MarioCPPP writes: [...] >>> I knew that "short" are aligned at addresses multiple of 2, "int" are >>> aligned at addresses multiple of 4, "long" are aligned at addresses >>> multiple of 8 bytes. >> If you mean that you know that's the case for the implementation >> you're >> using, that's fine. If you mean that it's true in general, it isn't. >> Different implementations can and do have different sizes and alignments >> for integer types. > > it is true for types used by QTcreator that has "explicit" fixed > byte-width types for 1,2,4,8 bytes. > They are likely some typedefs defined in math.h Not in . The code you posted above uses int32_t and int8_t which are defined in / . Their sizes and ranges are guaranteed by the C++ language definition (by reference to the C standard). Their alignments are not. Qt has similar typedefs qintN and quintN, for N = 8, 16, 32, 64. The Qt project was started in 1991, before / was available. Presumably if Qt were being created from scratch now, it would just use the standard types. A N-byte integer type often requires N-byte alignment, but it's not required. For example, 32-bit x86 systems typically use 4-byte alignment for 8-byte integers. For most purposes, you as a programmer don't need to know the alignment requirements for integer types; just let the compiler take care of it. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for XCOM Labs void Void(void) { Void(); } /* The recursive call of the void */