For faster navigation, this Iframe is preloading the Wikiwand page for stdalign.h.

stdalign.h

stdalign.h是C语言标准2011版新增加的C标准函数库头文件,为向后兼容目的定义了4个宏:

  • alignas 被扩展为_Alignas,_Alignas为C11的关键字。
  • alignof 被扩展为_Alignof,_Alignof为C11的关键字。
  • __alignas_is_defined 被扩展为1
  • __alignof_is_defined 被扩展为1

在C++11中,alignas与alignof是关键字。alignas用于变量定义、数据成员声明、class\struct\union的声明与定义。alignas不可用于基本类型的别名、数组类型等。alignas只能用于更严格(更大对齐值)。alignas的参数可以为数、类型。

alignof的参数为类型。

例子

[编辑]
#include <stdalign.h>
char alignas(double) buf[30];
char alignas(32) foo[7];

typedef struct { int a; double b; } S;
// alignof(S) == 8 为真

参考文献

[编辑]
  • C语言标准2011版:ISO/IEC 9899:2011第7.15节“Alignment <stdalign.h>”。
{{bottomLinkPreText}} {{bottomLinkText}}
stdalign.h
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?