summaryrefslogtreecommitdiff
path: root/tests/core/test_reinterpreted_ptrs.in
blob: 9865c61f26552b0abd521cd85bc10b12c33492be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>

class Foo {
 private:
  float bar;

 public:
  int baz;

  Foo() : bar(0), baz(4711) {};

  int getBar() const;
};

int Foo::getBar() const {
  return this->bar;
};

const Foo *magic1 = reinterpret_cast<Foo *>(0xDEAD111F);
const Foo *magic2 = reinterpret_cast<Foo *>(0xDEAD888F);

static void runTest() {

  const Foo *a = new Foo();
  const Foo *b = a;

  if (a->getBar() == 0) {
    if (a->baz == 4712)
      b = magic1;
    else
      b = magic2;
  }

  printf("%s\n",
         (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither")));
};

extern "C" {
int main(int argc, char **argv) { runTest(); }
}