File: main.c

package info (click to toggle)
cbmc 5.12-5
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 92,512 kB
  • sloc: cpp: 301,761; ansic: 51,699; java: 27,534; python: 5,113; yacc: 4,756; makefile: 3,184; lex: 2,749; sh: 1,347; perl: 555; xml: 404; pascal: 203; ada: 36
file content (62 lines) | stat: -rw-r--r-- 1,441 bytes parent folder | download | duplicates (4)
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
#include <assert.h>
#include <stdio.h>

int main()
{
  #ifdef __GNUC__
  _Complex c; // this is usually '_Complex double'
  c=1.0i+2;

  assert(__real__ c == 2);
  assert(__imag__ c == 1);

  _Complex double d;
  assert(sizeof(c)==sizeof(d));

  _Complex signed char char_complex, char_complex2;

  char_complex=0x3i-2;

  assert(sizeof(d)==sizeof(c));
  assert(sizeof(char_complex)==sizeof(signed char)*2);

  // The real part is stored first in memory on i386.
  // Need to find out about other architectures.
  #if defined(__i386__) || defined(__amd64__)
  assert(((signed char *)&char_complex)[0]==-2);
  assert(((signed char *)&char_complex)[1]==3);
  #endif

  assert(__real__ char_complex == -2);
  assert(__imag__ char_complex == 3);

  // the precedence of __imag__ is higher than that of +
  assert((__imag__ 1.0i + 1.0i) == 1.0i + 1.0);

  // complex conjugate
  char_complex2 = ~ char_complex;

  // __real__ something is an lvalue!
  __real__ char_complex = 100;
  assert(__real__ char_complex == 100);
  assert(__imag__ char_complex == 3);

  // can be incremented
  char_complex++;
  assert(__real__ char_complex == 101);
  assert(__imag__ char_complex == 3);

  // also separately
  (__real__ char_complex)++;
  assert(__real__ char_complex == 102);
  assert(__imag__ char_complex == 3);

  // casts to reals produce the real part
  assert((int) char_complex == 102);

  #else

  // Visual studio doesn't have it

  #endif
}