Example: pointer_arith_algebraic_properties_3_global.c

up: index
prev: pointer_arith_algebraic_properties_2_global.c
next: pointer_copy_memcpy.c

1
2
3
4
5
6
7
8
9
10
11
12
    #include <stdio.h>
    #include <inttypes.h>
    int y[2], x[2];
    int main() {
      int *p=(int*)(
        (((uintptr_t)&(x[0])) + ((uintptr_t)&(y[1])))
        -((uintptr_t)&(y[0])) );
      *p = 11;  // is this free of undefined behaviour?
      //(equivalent to the &x[0]+(&(y[1])-&(y[0])) version?)
      printf("x[1]=%d *p=%d\n",x[1],*p);
      return 0;
    }
[link to run test in Cerberus]

Experimental data (what does this mean?)

cerberus-concrete-PVI-plain x[1]=11 *p=11
cerberus-concrete-PVI-ae x[1]=11 *p=11
cerberus-concrete-PVI-ae-udi x[1]=11 *p=11
gcc-8.3-O0 x[1]=11 *p=11
gcc-8.3-O2 x[1]=11 *p=11
gcc-8.3-O3 x[1]=11 *p=11
gcc-8.3-O2-no-strict-aliasing x[1]=11 *p=11
gcc-8.3-O3-no-strict-aliasing x[1]=11 *p=11
clang-7.0.1-O0 x[1]=11 *p=11
clang-7.0.1-O2 x[1]=11 *p=11
clang-7.0.1-O3 x[1]=11 *p=11
clang-7.0.1-O2-no-strict-aliasing x[1]=11 *p=11
clang-7.0.1-O3-no-strict-aliasing x[1]=11 *p=11
icc-19-O0 x[1]=11 *p=11
icc-19-O2 x[1]=11 *p=11
icc-19-O3 x[1]=11 *p=11
icc-19-O2-no-strict-aliasing x[1]=11 *p=11
icc-19-O3-no-strict-aliasing x[1]=11 *p=11