File: main.cpp

package info (click to toggle)
cbmc 6.6.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,852 kB
  • sloc: cpp: 386,459; ansic: 114,466; java: 28,405; python: 6,003; yacc: 4,552; makefile: 4,041; lex: 2,487; xml: 2,388; sh: 2,050; perl: 557; pascal: 184; javascript: 163; ada: 36
file content (78 lines) | stat: -rw-r--r-- 1,275 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <cassert>

#define COPY

typedef unsigned uint;

template <class T, uint m>
class myarray {

  T elt[m];

public:
#if 0
  myarray &operator=(const myarray &other) {
    for (int i=0; i<m; i++) {
      elt[i] = other.elt[i];
    }
    return *this;
  }
#endif

  T& operator[] (int idx) {
    return elt[idx];
  }
};

#ifdef COPY
myarray<uint, 3> rev3u(myarray<uint, 3> x) {
  myarray<uint, 3> y;
  y[0] = x[2];
  y[1] = x[1];
  y[2] = x[0];
  return y;
}

#else

void rev3u(myarray<uint, 3> x, myarray<uint, 3> &y) {
  y[0] = x[2];
  y[1] = x[1];
  y[2] = x[0];
}
#endif

extern bool arbb();
extern uint arbu();

int main(void) {
  myarray<bool, 4> arrb;

  for (int i=0; i<4; i++) {
    bool cond = (i%2 == 0);
    arrb[i] = cond;
  }

  assert(arrb[0] == true);
  assert(arrb[1] == false);
  assert(arrb[2] == true);
  assert(arrb[3] == false);

  myarray<uint, 3> arru;
  for (int i=0; i<3; i++) {
    arru[i] = arbu();
  }

  myarray<uint, 3> arru2;
#ifdef COPY
  arru2 = rev3u(arru); //problem: copy constructor refuses to copy array (solved)
                       //new problem: byte_extract_little_endian ignored
#else
  rev3u(arru,arru2);
#endif
  assert (arru2[0] == arru[2]);
  assert (arru2[1] == arru[1]);
  assert (arru2[2] == arru[0]);

  return 0;
}