#include <stdio.h> int main(char* argv[], int argc) { struct V { char buf1[10]; int b; char buf2[10]; } var; void *ptr = &var.b; printf("%d\n", __builtin_object_size(ptr, 0)); printf("%d\n", __builtin_object_size(ptr, 1)); printf("%d\n", __builtin_object_size(ptr, 2)); printf("%d\n", __builtin_object_size(ptr, 3)); printf("%d\n", sizeof(var)); return 0; }
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
The built-in functions described below yield the best results when used together and when optimization is enabled.
$ ./test16416428
$ ./test
16
4
28