0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++ > stdint.h > sizeof(int[][3])とsizeof(uint8_t[][3]) > 48と12

Last updated at Posted at 2017-01-15
動作環境
ideone > C++14
C++ Builder XE4でも確認

C++ Builder XE4で実装していたプログラムにてstdint.hを使い始めて、はまった。

#include <iostream>
using namespace std;
#include <stdint.h>
 
static const int kTable_cond1[][3] = {
	{ 1, 0, 0 },
	{ 0, 1, 0 },
	{ 0, 0, 1 },
	{ 0, 1, 1 }
};
static const uint8_t kTable_cond2[][3] = {
	{ 1, 0, 0 },
	{ 0, 1, 0 },
	{ 0, 0, 1 },
	{ 0, 1, 1 }
};
 
int main() {
	printf("%zu\n", sizeof(kTable_cond1));
	printf("%zu\n", sizeof(kTable_cond2));
	return 0;
}
結果
48
12

上記の違いにより
int tbl[3];
int sizeCond = sizeof(kTable_conditions) / sizeof(tbl);
の結果が4と1の違いが出て、はまった。


@SaitoAtsushi さんに上記に関する詳細記事を用意いただきました。 http://qiita.com/SaitoAtsushi/items/ee17466c464fb7a270d2

感謝です。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?