C言語なら俺に聞け! Part 110
■ このスレッドは過去ログ倉庫に格納されています
0148デフォルトの名無しさん
2005/07/08(金) 00:28:49>>118 だろ?
行数が多いって怒られちゃったよ...orz
/* C FAQ 2.14, 2.15 */
#include <stddef.h>
#include <stdio.h>
#ifndef offsetof
#define offsetof(type, mem) ((size_t) \
((char *)&((type *)0)->mem - (char *)(type *)0))
#endif /* !offsetof */
typedef struct TYPE {
char *a;
int b;
int c;
int d;
} TYPE;
void hoge(TYPE* type, size_t offset) {
type->a = ((char*)type) + offset;
}
int main() {
TYPE a = { NULL, 3, 2, 1 };
hoge(&a, offsetof(TYPE, b));
printf("%d\n", (int)*a.a);
hoge(&a, offsetof(TYPE, c));
printf("%d\n", (int)*a.a);
hoge(&a, offsetof(TYPE, d));
printf("%d\n", (int)*a.a);
}
■ このスレッドは過去ログ倉庫に格納されています