]>
Commit | Line | Data |
---|---|---|
885824d3 | 1 | # include <stdio.h> |
2 | # include <strings.h> | |
3 | # include <stdlib.h> | |
4 | # include <assert.h> | |
5 | ||
6 | typedef struct | |
7 | { | |
8 | int x; | |
9 | char *name; | |
10 | } record; | |
11 | ||
12 | record copyrecord (record x) | |
13 | { | |
14 | record copy = x; | |
15 | return copy; /* 1. Released storage x.name reachable from parameter at ... */ | |
16 | } | |
17 | ||
18 | record copyrecord2 (record x) | |
19 | { | |
20 | record copy; | |
21 | ||
22 | copy = x; | |
23 | return copy; /* 2. Released storage x.name reachable from parameter at ... */ | |
24 | } | |
25 | ||
26 | record copyrecord3 (record x) | |
27 | { | |
28 | return x; /* 3. Released storage x.name reachable from parameter at ... */ | |
29 | } | |
30 | ||
31 | int main () | |
32 | { | |
33 | record r; | |
34 | record rc; | |
35 | ||
36 | r.x = 3; | |
37 | r.name = (char *) malloc (sizeof (char) * 100); | |
38 | assert (r.name != NULL); | |
39 | strcpy (r.name, "yo"); | |
40 | ||
41 | rc = r; | |
42 | ||
43 | printf ("rc: %s", rc.name); | |
44 | ||
45 | return r.x; /* 4. Only storage rc.name (type char *) derived from variable ... */ | |
46 | } |