-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest02.cpp
110 lines (98 loc) · 1.99 KB
/
test02.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# include <cstdlib>
# include <iostream>
using namespace std;
void junk_data ( );
int main ( );
//****************************************************************************80
int main ( )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for TEST01.
//
// Discussion:
//
// TEST02 has some uninitialized data.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 19 May 2011
//
{
cout << "\n";
cout << "TEST02:\n";
cout << " C++ version\n";
cout << " A sample code for analysis by VALGRIND.\n";
junk_data ( );
//
// Terminate.
//
cout << "\n";
cout << "TEST02\n";
cout << " Normal end of execution.\n";
return 0;
}
//****************************************************************************80
void junk_data ( )
//****************************************************************************80
//
// Purpose:
//
// JUNK_DATA has some uninitialized variables.
//
// Discussion:
//
// VALGRIND's MEMCHECK program monitors uninitialized variables, but does
// not complain unless such a variable is used in a way that means its
// value affects the program's results, that is, the value is printed,
// or computed with. Simply copying the unitialized data to another variable
// is of no concern.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 18 May 2011
//
{
int i;
int *x;
x = new int[10];
//
// X = { 0, 1, 2, 3, 4, ?a, ?b, ?c, ?d, ?e }.
//
for ( i = 0; i < 5; i++ )
{
x[i] = i;
}
//
// Copy some values.
// X = { 0, 1, ?c, 3, 4, ?b, ?b, ?c, ?d, ?e }.
//
x[2] = x[7];
x[5] = x[6];
//
// Modify some uninitialized entries.
// Memcheck doesn't seem to care about this.
//
for ( i = 0; i < 10; i++ )
{
x[i] = 2 * x[i];
}
//
// Print X.
//
for ( i = 0; i < 10; i++ )
{
cout << " " << i << " " << x[i] << "\n";
}
delete [] x;
return;
}