#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; }
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
The built-in functions described below yield the best results when used together and when optimization is enabled.
$ ./test16416428
$ ./test
16
4
28