Skip to content

Instantly share code, notes, and snippets.

@cuihaoleo
Created August 29, 2015 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuihaoleo/c52141d1a35479094d57 to your computer and use it in GitHub Desktop.
Save cuihaoleo/c52141d1a35479094d57 to your computer and use it in GitHub Desktop.
test struct init
#include <stdio.h>
struct test {
int a, b, c;
};
int main() {
struct test st = {
.b = 15,
};
printf("%d %d %d", st.a, st.b, st.c);
return 0;
}
.file "a.c"
.section .rodata
.LC0:
.string "%d %d %d"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movq $0, -16(%rbp) // st.a = st.b = 0
movl $0, -8(%rbp) // st.c = 0
movl $15, -12(%rbp) // st.b
movl -8(%rbp), %ecx
movl -12(%rbp), %edx
movl -16(%rbp), %eax
movl %eax, %esi
movl $.LC0, %edi
movl $0, %eax
call printf
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 5.2.0"
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment