Ruby: include/ruby/internal/stdalign.h File Reference

Ruby 3.3.5p100 (2024-09-03 revision ef084cc8f4958c1b6e4ead99136631bef6d8ddba)

Macros
stdalign.h File Reference

Defines RBIMPL_ALIGNAS / RBIMPL_ALIGNOF. More...

`#include "ruby/internal/config.h"`
`#include "ruby/internal/compiler_is.h"`
`#include "ruby/internal/has/attribute.h"`
`#include "ruby/internal/has/declspec_attribute.h"`
`#include "ruby/internal/has/feature.h"`

Go to the source code of this file.

## Macros
#define | RBIMPL_ALIGNAS alignas
| Wraps (or simulates) `alignas`.
#define | RBIMPL_ALIGNOF alignof
| Wraps (or simulates) `alignof`.

## Detailed Description

Defines RBIMPL_ALIGNAS / RBIMPL_ALIGNOF.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file stdalign.h.

## Macro Definition Documentation

## ◆ RBIMPL_ALIGNAS

#define RBIMPL_ALIGNAS alignas

Wraps (or simulates) `alignas`.

This is C++11's `alignas` and is different from C11 `_Alignas`. For instance,

typedef struct alignas(128) foo { int foo } foo;

is a valid C++ while

typedef struct _Alignas(128) foo { int foo } foo;

is an invalid C because:

- You cannot `struct _Alignas`.
- A `typedef` cannot have alignments.

Definition at line 57 of file stdalign.h.

## ◆ RBIMPL_ALIGNOF

#define RBIMPL_ALIGNOF alignof

Wraps (or simulates) `alignof`.

We want C11's `_Alignof`. However in spite of its clear language, compilers (including GCC and clang) tend to have buggy implementations. We have to avoid such things to resort to our own version.

See also
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69560
  https://bugs.llvm.org/show_bug.cgi?id=26547

Definition at line 87 of file stdalign.h.