-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct.c
74 lines (65 loc) · 1.59 KB
/
struct.c
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
/****************************************************************
* Experiments in struct wrapping
*
* Trying to find a way of supporting the common idiom of
* defining a struct W with a single field of type T
*
* struct W { T x; };
*
* as a type-checkable alternative to writing
*
* typedef T W;
*
* Copyright Alastair Reid 2020
* SPDX-Licence-Identifier: BSD-3-Clause
****************************************************************/
#include "stdlib.h"
typedef int T;
struct W {
T t;
};
#if 1
// Produces this error
// Dereferencing pointers of type struct W is not yet supported.
T w_to_t(struct W w)
//@ requires true;
//@ ensures true;
// The following 'ensures' clause is not allowed. Produces this error:
// Taking the address of this expression is not supported.
// ensures result == w.t;
{
return w.t;
}
#endif
#if 0
// Produces this error
// Cannot consume points-to chunk for variable of type 'struct W'
struct W t_to_w(T t)
//@ requires true;
//@ ensures true;
// ensures result.t == t;
{
struct W w;
w.t = t;
return w;
}
#endif
/****************************************************************
* Typedef experiments
*
* (These do not make any difference)
****************************************************************/
typedef struct W W_t;
#if 0
// Produces this error
// Dereferencing pointers of type struct W is not yet supported.
T w_to_t2(W_t w)
//@ requires true;
//@ ensures true;
{
return w.t;
}
#endif
/****************************************************************
* End
****************************************************************/