blog 文章

2016/09/07

simple c interpreter - pointer test

simple c interpreter 支援指標操作, 一樣會 Segmentation fault。
pointer.test
descent@u64:simple_compiler$ cat test_pattern/p6.c
// pointer test
int main()
{
  int x,y;
  int a,b;
  int *p;

  x=987;
  y=29;
  p=&x;

  //p = 100;

  a=*p;

  //printf("a: %d\n", a);

  p=&y;
  a=*p;

  //printf("new a: %d\n", a);
  //printf("a: %d, p: %p\n", a, p); 
  printf("&x: %p\n", &x);
  p=100;
  printf("p: %d\n", p); 
  *p;

}
descent@u64:simple_compiler$ ./c_parser < test_pattern/p6.c 
\tree( root( prog( main |int |func |global( func_body( var(x |int)(y |int))( var(a |int)(b |int))( var(p |ptr<1> |int))( =(x)(987))( =(y)(29))( =(p)( &(x)))( =(a)( *(p)))( =(p)( &(y)))( =(a)( *(p)))( printf(&x: \%p\\n)( &(x)))( =(p)(100))( printf(p: \%d\\n)(p))( *(p))))(main)))
 op: root
&x: 1632ff0
p: 100
Segmentation fault (core dumped)

沒有留言:

張貼留言