Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtypes.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// Copyright (C) 2022 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QTYPES_H
6#define QTYPES_H
7
8#include <QtCore/qprocessordetection.h>
9#include <QtCore/qtconfigmacros.h>
10
11#ifdef __cplusplus
12# include <cstddef>
13# include <cstdint>
14#else
15# include <assert.h>
16#endif
17
18#if 0
19#pragma qt_class(QtTypes)
20#pragma qt_class(QIntegerForSize)
21#pragma qt_sync_stop_processing
22#endif
23
24/*
25 Useful type definitions for Qt
26*/
27typedef unsigned char uchar;
28typedef unsigned short ushort;
29typedef unsigned int uint;
30typedef unsigned long ulong;
31
33
34/*
35 Size-dependent types (architecture-dependent byte order)
36
37 Make sure to update QMetaType when changing these typedefs
38*/
39
40typedef signed char qint8; /* 8 bit signed */
41typedef unsigned char quint8; /* 8 bit unsigned */
42typedef short qint16; /* 16 bit signed */
43typedef unsigned short quint16; /* 16 bit unsigned */
44typedef int qint32; /* 32 bit signed */
45typedef unsigned int quint32; /* 32 bit unsigned */
46// Unlike LL / ULL in C++, for historical reasons, we force the
47// result to be of the requested type.
48#ifdef __cplusplus
49# define Q_INT64_C(c) static_cast<long long>(c ## LL) /* signed 64 bit constant */
50# define Q_UINT64_C(c) static_cast<unsigned long long>(c ## ULL) /* unsigned 64 bit constant */
51#else
52# define Q_INT64_C(c) ((long long)(c ## LL)) /* signed 64 bit constant */
53# define Q_UINT64_C(c) ((unsigned long long)(c ## ULL)) /* unsigned 64 bit constant */
54#endif
55typedef long long qint64; /* 64 bit signed */
56typedef unsigned long long quint64; /* 64 bit unsigned */
57
60
61#if defined(__SIZEOF_INT128__)
62__extension__ typedef __int128_t qint128;
63__extension__ typedef __uint128_t quint128;
64#endif
65
66#ifndef __cplusplus
67// In C++ mode, we define below using QIntegerForSize template
68static_assert(sizeof(ptrdiff_t) == sizeof(size_t), "Weird ptrdiff_t and size_t definitions");
69typedef ptrdiff_t qptrdiff;
70typedef ptrdiff_t qsizetype;
71typedef ptrdiff_t qintptr;
72typedef size_t quintptr;
73
74#define PRIdQPTRDIFF "td"
75#define PRIiQPTRDIFF "ti"
76
77#define PRIdQSIZETYPE "td"
78#define PRIiQSIZETYPE "ti"
79
80#define PRIdQINTPTR "td"
81#define PRIiQINTPTR "ti"
82
83#define PRIuQUINTPTR "zu"
84#define PRIoQUINTPTR "zo"
85#define PRIxQUINTPTR "zx"
86#define PRIXQUINTPTR "zX"
87#endif
88
89#if defined(QT_COORD_TYPE)
90typedef QT_COORD_TYPE qreal;
91#else
92typedef double qreal;
93#endif
94
95#if defined(__cplusplus)
96/*
97 quintptr are qptrdiff is guaranteed to be the same size as a pointer, i.e.
98
99 sizeof(void *) == sizeof(quintptr)
100 && sizeof(void *) == sizeof(qptrdiff)
101
102 While size_t and qsizetype are not guaranteed to be the same size as a pointer,
103 they usually are and we do check for that in qtypes.cpp, just to be sure.
104*/
105template <int> struct QIntegerForSize;
106template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qint8 Signed; };
107template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
108template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
109template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
110#if defined(Q_CC_GNU) && defined(__SIZEOF_INT128__)
111template <> struct QIntegerForSize<16> { typedef quint128 Unsigned; typedef qint128 Signed; };
112#endif
113template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
114typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
115typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint;
116typedef QIntegerForSizeof<void *>::Unsigned quintptr;
117typedef QIntegerForSizeof<void *>::Signed qptrdiff;
118typedef qptrdiff qintptr;
119using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
120
121// These custom definitions are necessary as we're not defining our
122// datatypes in terms of the language ones, but in terms of integer
123// types that have the sime size. For instance, on a 32-bit platform,
124// qptrdiff is int, while ptrdiff_t may be aliased to long; therefore
125// using %td to print a qptrdiff would be wrong (and raise -Wformat
126// warnings), although both int and long have same bit size on that
127// platform.
128//
129// We know that sizeof(size_t) == sizeof(void *) == sizeof(qptrdiff).
130#if SIZE_MAX == 0xffffffffULL
131#define PRIuQUINTPTR "u"
132#define PRIoQUINTPTR "o"
133#define PRIxQUINTPTR "x"
134#define PRIXQUINTPTR "X"
135
136#define PRIdQPTRDIFF "d"
137#define PRIiQPTRDIFF "i"
138
139#define PRIdQINTPTR "d"
140#define PRIiQINTPTR "i"
141
142#define PRIdQSIZETYPE "d"
143#define PRIiQSIZETYPE "i"
144#elif SIZE_MAX == 0xffffffffffffffffULL
145#define PRIuQUINTPTR "llu"
146#define PRIoQUINTPTR "llo"
147#define PRIxQUINTPTR "llx"
148#define PRIXQUINTPTR "llX"
149
150#define PRIdQPTRDIFF "lld"
151#define PRIiQPTRDIFF "lli"
152
153#define PRIdQINTPTR "lld"
154#define PRIiQINTPTR "lli"
155
156#define PRIdQSIZETYPE "lld"
157#define PRIiQSIZETYPE "lli"
158#else
159#error Unsupported platform (unknown value for SIZE_MAX)
160#endif
161
162#endif // __cplusplus
163
165
166#endif // QTYPES_H
Combined button and popup list for selecting options.
unsigned int quint32
Definition qtypes.h:45
unsigned char uchar
Definition qtypes.h:27
short qint16
Definition qtypes.h:42
unsigned short quint16
Definition qtypes.h:43
size_t quintptr
Definition qtypes.h:72
int qint32
Definition qtypes.h:44
unsigned long ulong
Definition qtypes.h:30
ptrdiff_t qptrdiff
Definition qtypes.h:69
quint64 qulonglong
Definition qtypes.h:59
unsigned long long quint64
Definition qtypes.h:56
ptrdiff_t qsizetype
Definition qtypes.h:70
unsigned int uint
Definition qtypes.h:29
long long qint64
Definition qtypes.h:55
unsigned short ushort
Definition qtypes.h:28
QT_BEGIN_NAMESPACE typedef signed char qint8
Definition qtypes.h:40
double qreal
Definition qtypes.h:92
unsigned char quint8
Definition qtypes.h:41
qint64 qlonglong
Definition qtypes.h:58
ptrdiff_t qintptr
Definition qtypes.h:71