Access elements in array of struct

 

#include <stdio.h>

struct packet_buf {
	char buf[16];
} __attribute__((aligned(16)));

struct packet_buf buf_ring[4];

int main(int argc, const char *argv[]) {
	int i;

	printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
	// &buf_ring[i] and buf_ring[i].buf have the same value
	for (i = 0; i < 4; i++) {
		printf("&buf_ring[%d]: %p, ", i, &buf_ring[i]);
		printf("buf_ring[%d].buf: %p\n", i, buf_ring[i].buf);
		if (&buf_ring[i] != buf_ring[i].buf)
			printf("panic\n");
	}

	return 0;
}

你可能感兴趣的:(element)