LINUX.ORG.RU

История изменений

Исправление utf8nowhere, (текущая версия) :

Потому что это константное выражение

Cast operators in an integer constant expression shall only convert arithmetic types to integer types?

его можно записать в constexpr

#include <stddef.h>

struct S { int x; };

constexpr auto x = (size_t)(&((struct S*)0)->x);

clang:

<source>:5:16: error: constexpr variable 'x' must be initialized by a constant expression
    5 | constexpr auto x = (size_t)(&((struct S*)0)->x);
      |                ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:5:20: note: this conversion is not allowed in a constant expression
    5 | constexpr auto x = (size_t)(&((struct S*)0)->x);
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

gcc:

<source>:5:20: error: 'constexpr' integer initializer is not an integer constant expression
    5 | constexpr auto x = (size_t)(&((struct S*)0)->x);
      |                    ^

https://godbolt.org/z/4oehGrG1j

Кастомный таргет со своей libc

freestanding-хедеры это часть кросс-компилятора

stddef.h тут пишем тоже мы

ССЗБ?

Исходная версия utf8nowhere, :

Потому что это константное выражение

Cast operators in an integer constant expression shall only convert arithmetic types to integer types?

его можно записать в constexpr

#include <stddef.h>

struct S { int x; };

constexpr auto x = (size_t)(&((struct S*)0)->x);

clang:

<source>:5:16: error: constexpr variable 'x' must be initialized by a constant expression
    5 | constexpr auto x = (size_t)(&((struct S*)0)->x);
      |                ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:5:20: note: this conversion is not allowed in a constant expression
    5 | constexpr auto x = (size_t)(&((struct S*)0)->x);
      |

gcc:

<source>:5:20: error: 'constexpr' integer initializer is not an integer constant expression
    5 | constexpr auto x = (size_t)(&((struct S*)0)->x);
      |

https://godbolt.org/z/4oehGrG1j

Кастомный таргет со своей libc

freestanding-хедеры это часть кросс-компилятора

stddef.h тут пишем тоже мы

ССЗБ?