回答編集履歴
1
別のを追加
test
CHANGED
@@ -71,3 +71,81 @@
|
|
71
71
|
}
|
72
72
|
|
73
73
|
```
|
74
|
+
|
75
|
+
---
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
別の.
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
uint32_t Get_Member_value_as_uint32( uint8_t *pStructHead, const size_t *SizeMap, uint8_t select )
|
84
|
+
|
85
|
+
{
|
86
|
+
|
87
|
+
uint8_t *pos = pStructHead;
|
88
|
+
|
89
|
+
for( uint8_t i=0; i<select; ++i ){ pos += SizeMap[i]; }
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
switch( SizeMap[select] )
|
94
|
+
|
95
|
+
{
|
96
|
+
|
97
|
+
case 4: return *( (uint32_t*)pos );
|
98
|
+
|
99
|
+
case 2: return *( (uint16_t*)pos );
|
100
|
+
|
101
|
+
case 1: //fall through
|
102
|
+
|
103
|
+
default: return *pos;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
//-----
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
#pragma pack(push,1) //※環境次第
|
116
|
+
|
117
|
+
typedef struct {
|
118
|
+
|
119
|
+
uint32_t a;
|
120
|
+
|
121
|
+
uint8_t b;
|
122
|
+
|
123
|
+
uint16_t c;
|
124
|
+
|
125
|
+
}hoge_m;
|
126
|
+
|
127
|
+
#pragma pack(pop) //※環境次第
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
//↑のstructを実装した人間は,
|
132
|
+
|
133
|
+
//せめて,このような関数もセットで書くくらいの労力を費やしてもよいのではなイカ?
|
134
|
+
|
135
|
+
//(あるいはもう機械的に何かで出力すればよくね?)
|
136
|
+
|
137
|
+
uint32_t hoge_func(hoge_m *hoge_para, uint8_t select)
|
138
|
+
|
139
|
+
{
|
140
|
+
|
141
|
+
static const size_t MemSize[] = { 4, 1, 2 }; //各メンバのサイズ
|
142
|
+
|
143
|
+
return Get_Member_value_as_uint32( (uint8_t*)hoge_para, MemSize, select );
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
//-----
|
150
|
+
|
151
|
+
```
|