Skip to content

Instantly share code, notes, and snippets.

@naohaq
Created November 7, 2012 03:09
Show Gist options
  • Save naohaq/4029366 to your computer and use it in GitHub Desktop.
Save naohaq/4029366 to your computer and use it in GitHub Desktop.
A compilation result of cast "const int *" into "int *"
#include <stdio.h>
void
f(int * p)
{
*p = 2;
}
int
main(int argc, char * argv[])
{
const int x = 1;
f(&x);
printf("%d\n", x);
return 0;
}
.file "ptr.c"
.text
.p2align 4,,15
.globl f
.type f, @function
f:
.LFB11:
.cfi_startproc
movl 4(%esp), %eax
movl $2, (%eax)
ret
.cfi_endproc
.LFE11:
.size f, .-f
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d\n"
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB12:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
andl $-16, %esp
subl $16, %esp
movl $2, 4(%esp)
movl $.LC0, (%esp)
call printf
xorl %eax, %eax
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
.LFE12:
.size main, .-main
.ident "GCC: (Debian 4.7.1-7) 4.7.1"
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment