Skip to content

Commit ce5d1c0

Browse files
committed
udpate size_t
1 parent 2c2a572 commit ce5d1c0

7 files changed

+13
-13
lines changed

week06/Lab06.pdf

656 KB
Binary file not shown.

week06/Lab06.pptx

691 KB
Binary file not shown.

week06/Lecture06.pdf

16.1 KB
Binary file not shown.

week06/Lecture06.pptx

48.3 KB
Binary file not shown.

week06/examples/function.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33

44
struct Matrix
55
{
6-
int rows;
7-
int cols;
6+
size_t rows;
7+
size_t cols;
88
float * pData;
99
};
1010

1111
float matrix_max(struct Matrix mat)
1212
{
1313
float max = FLT_MIN;
1414
//find max value of mat
15-
for(int r = 0; r < mat.rows; r++)
16-
for (int c = 0; c < mat.cols; c++)
15+
for(size_t r = 0; r < mat.rows; r++)
16+
for (size_t c = 0; c < mat.cols; c++)
1717
{
1818
float val = mat.pData[ r * mat.cols + c];
1919
max = ( max > val ? max : val);
2020
}
2121
return max;
2222
}
2323

24-
Matrix * create_matrix(int rows, int cols)
24+
Matrix * create_matrix(size_t rows, size_t cols)
2525
{
2626
Matrix * p = new Matrix{rows, cols};
2727
p->pData = new float[p->rows * p->cols]{1.f, 2.f, 3.f};

week06/examples/nofunction.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
struct Matrix
55
{
6-
int rows;
7-
int cols;
6+
size_t rows;
7+
size_t cols;
88
float * pData;
99
};
1010

@@ -28,8 +28,8 @@ int main()
2828
float maxc = FLT_MIN;
2929

3030
//find max value of matA
31-
for(int r = 0; r < matA.rows; r++)
32-
for (int c = 0; c < matA.cols; c++)
31+
for(size_t r = 0; r < matA.rows; r++)
32+
for (size_t c = 0; c < matA.cols; c++)
3333
{
3434
float val = matA.pData[ r * matA.cols + c];
3535
maxa = ( maxa > val ? maxa : val);

week06/examples/param-reference.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
struct Matrix
55
{
6-
int rows;
7-
int cols;
6+
size_t rows;
7+
size_t cols;
88
float * pData;
99
};
1010

1111
float matrix_max(const struct Matrix & mat)
1212
{
1313
float max = FLT_MIN;
1414
//find max value of mat
15-
for(int r = 0; r < mat.rows; r++)
16-
for (int c = 0; c < mat.cols; c++)
15+
for(size_t r = 0; r < mat.rows; r++)
16+
for (size_t c = 0; c < mat.cols; c++)
1717
{
1818
float val = mat.pData[ r * mat.cols + c];
1919
max = ( max > val ? max : val);

0 commit comments

Comments
 (0)