The OpenGL specification says that `GLint` should be 32 bits wide, but gl.xml naively defines it as` int` instead of `int32_t`. What for?

The OpenGL specification (glspec45.core.pdf) defines the exact bit width for all types GL...:

2.2.1 Data Transformation for State Setting Commands
...
The implementation must accurately use the number of bits indicated in the table to represent the GL type.
...

But the so-called OpenGL registry (gl.xml is the official analytical specification of the OpenGL API) naively defines these types as aliases for the corresponding C types.

...
<type>typedef short <name>GLshort</name>;</type>
<type>typedef int <name>GLint</name>;</type>
<type>typedef int <name>GLclampx</name>;</type>
...

This is potentially dangerous.

Why weren't fixed-width types used instead?

? ?

, / OpenGL, ?

+4
2

.

, .

?

, / , , . GCC, Clang, V++ . Windows, MacOS, Linux, Android, iOS ABI.

C ++. , . , , OpenGL .

?

OpenGL . : C99/++ 11; OpenGL 1992 .

?

1992 ++ . " " ? , OpenGL C, C .

, / OpenGL, ?

, gl.xml, .

+5

, , glew.h, OpenGL .

:

#if defined(_MSC_VER) && _MSC_VER < 1400
typedef __int64 GLint64EXT;
typedef unsigned __int64 GLuint64EXT;
#elif defined(_MSC_VER) || defined(__BORLANDC__)
typedef signed long long GLint64EXT;
typedef unsigned long long GLuint64EXT;
#else
#  if defined(__MINGW32__) || defined(__CYGWIN__)
#include <inttypes.h>
#  endif
typedef int64_t GLint64EXT;
typedef uint64_t GLuint64EXT;
#endif
0

Source: https://habr.com/ru/post/1664835/


All Articles