


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An in-depth look into c structs, their memory representation, and data alignment. It covers various aspects such as copying structs, typedefs, linked lists, and unaligned data. The author also discusses best practices for saving space and working with floating-point numbers using ymm/xmm registers.
What you will learn
Typology: Lecture notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
Sean Barker
1
struct rec { int a[4]; size_t i; struct rec next; };* struct rec x; struct rec y; x.i = 5; x.a[1] = 2; x.next = &y; y = x; // copy full struct struct rec* z; z = &y; // just a pointer copy // form 1 (*z).i = 7; // NOT z.i = 7; // form 2 (preferred) z->i = 7;
// give type T another name: U typedef T U; // example: defines a type “struct rec” // and typedefs it with another name “rec” typedef struct rec { ... } rec; rec x; // now can omit “struct” x.i = 5; rec* p = (rec*) malloc(sizeof(rec)); p->i = 3;
Sean Barker
3 .L11: # loop: movslq 16(%rdi), %rax # i = M[r+16] movl %esi, (%rdi,%rax,4) # M[r+4i] = val movq 24(%rdi), %rdi # r = M[r+24] testq %rdi, %rdi # Test r jne .L11 # if !=0 goto loop void set_val (struct rec r, int val) { while (r) { int i = r->i; r->a[i] = val; r = r->next; } } Register Value %rdi r %rsi val struct rec { int a[4]; int i; struct rec* next; }; Element i r i next 0 16 24 32 a**
*struct S1 { char c; int i[2]; double v; } p;
c i[0] i[1] v p p+1 p+5 p+9 p+
c 3 bytes^ i[0] i[1] 4 bytes v
n 16 single-byte integers n 8 16-bit integers n 4 32-bit integers n 4 single-precision floats n 2 double-precision floats n 1 single-precision float n 1 double-precision float