-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect_structs.cpp
More file actions
executable file
·42 lines (35 loc) · 1.46 KB
/
inspect_structs.cpp
File metadata and controls
executable file
·42 lines (35 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// structs.cpp
// Runner that prints all sizes and offsets using the generated AutoInspectors.inc
#include <cstddef>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
// Minimal registry so each generated inspector self-registers
namespace ai {
using Fn = void(*)();
inline std::vector<std::pair<const char*, Fn>>& reg() {
static std::vector<std::pair<const char*, Fn>> r;
return r;
}
inline void add(const char* name, Fn fn) { reg().emplace_back(name, fn); }
}
// Macros consumed by AutoInspectors.inc, and auto-register
#define AI_BEGIN(Name, Size) \
static void Inspect_##Name() { \
std::cout << #Name << " (sizeof=" << (Size) << ")\n";
#define AI_FIELD(Rec, Field, TypeSpelling, ByteOffset) \
std::cout << " " #Field " @+" << (ByteOffset) << " : " \
<< (TypeSpelling) << "\n";
#define AI_END(Name) \
} \
static const int _ai_reg_##Name = (ai::add(#Name, &Inspect_##Name), 0);
// Pull in generated records/fields
#include "AutoInspectors.inc"
int main() {
std::cout << "=== Struct Sizes and Field Offsets ===\n";
for (const auto& it : ai::reg()) {
it.second();
}
return 0;
}