Skip to content

Instantly share code, notes, and snippets.

@uhziel
Created September 21, 2020 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhziel/52af43f2d99a1b4c47d9eda1922b5634 to your computer and use it in GitHub Desktop.
Save uhziel/52af43f2d99a1b4c47d9eda1922b5634 to your computer and use it in GitHub Desktop.
#include <iostream> // std::cout
enum FruitType
{
Apple,
Pear,
};
int main () {
FruitType enum_type = Pear;
int int_type = 0;
std::cout << "sizeof(FruitType)" << sizeof(enum_type) << std::endl;
std::cout << "sizeof(int_type)" << sizeof(int_type) << std::endl;
return 0;
}
@uhziel
Copy link
Author

uhziel commented Sep 21, 2020

[root@TENCENT64 /tmp]# g++ size.cpp
[root@TENCENT64 /tmp]# ./a.out
sizeof(FruitType)4
sizeof(int_type)4
[root@TENCENT64 /tmp]# g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-5)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@uhziel
Copy link
Author

uhziel commented Sep 21, 2020

D:\workspace>cl size.cpp
用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.15.26730 版
版权所有(C) Microsoft Corporation。保留所有权利。

size.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include\xlocale(319): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
Microsoft (R) Incremental Linker Version 14.15.26730.0
Copyright (C) Microsoft Corporation. All rights reserved.

/out:size.exe
size.obj

D:\workspace>size.exe
sizeof(FruitType)4
sizeof(int_type)4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment