Skip to content

Instantly share code, notes, and snippets.

@MasazI
Created May 21, 2015 14:33
Show Gist options
  • Save MasazI/f52666729dcf7c84869a to your computer and use it in GitHub Desktop.
Save MasazI/f52666729dcf7c84869a to your computer and use it in GitHub Desktop.
alignment.cpp
//
// alignment.cpp
// CplusplusPractice
//
// Created by masai on 2015/05/21.
// Copyright (c) 2015年 masai. All rights reserved.
//
#include <iostream>
using namespace std;
// 構造体のすべてのメンバを4バイト単位で配置する例
struct S{
alignas(uint32_t) uint8_t a_;
alignas(uint32_t) uint16_t b_;
alignas(uint32_t) uint32_t c_;
};
int main(){
// int型のアライメント要求
cout << alignof(int) << endl;
cout << alignof(uint32_t) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment