背景
CやC++でFPGAやハードウェアを制御する場合、まずは自分の環境でデータの型を確認した方が良い。そういう場合のちょっとしたコードです。
サンプルコード
どこでもよいので、下記を挿入する。
double *dbl_pnt;
int *int_pnt;
long *long_pnt;
long long *longlong_pnt;
printf("> Basic data type:\n");
printf(" sizeof (char) = %d\n", sizeof(char));
printf(" sizeof (uchar) = %d\n", sizeof(unsigned char));
printf(" sizeof (short) = %d\n", sizeof(short));
printf(" sizeof (ushort) = %d\n", sizeof(unsigned short));
printf(" sizeof (int) = %d\n", sizeof(int));
printf(" sizeof (*int) = %d\n", sizeof(int_pnt));
printf(" sizeof (float) = %d\n", sizeof(float));
printf(" sizeof (double) = %d\n", sizeof(double));
printf(" sizeof (*double) = %d\n", sizeof(dbl_pnt));
printf(" sizeof (long) = %d\n", sizeof(long));
printf(" sizeof (*long) = %d\n", sizeof(long_pnt));
printf(" sizeof (long long ) = %d\n", sizeof(long long ));
printf(" sizeof (*long long ) = %d\n", sizeof(longlong_pnt));
出力結果は、
> Basic data type:
sizeof (char) = 1
sizeof (uchar) = 1
sizeof (short) = 2
sizeof (ushort) = 2
sizeof (int) = 4
sizeof (*int) = 8
sizeof (float) = 4
sizeof (double) = 8
sizeof (*double) = 8
sizeof (long) = 8
sizeof (*long) = 8
sizeof (long long ) = 8
sizeof (*long long ) = 8
上記の結果は、下記の環境で取得された。
> gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
参考資料
- 3次元磁気流体シミュレーションコード pluto の main.c