Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compilation

- run g++ compilation command
g++ Matrix.cpp -o Matrix
- output
Matrix 1:
1 2 3 
4 5 6 
Matrix 2:
7 8 
9 10 
11 12 
Result of multiplication:
33 36 
66 72 
*The output of multiplication is wrong

Debugging

After Take a look of code I suspect this Line:

43 result.data[i][j] = data[i][k] * other.data[k][j];

so lets start c++ debugger

- recompile with debugger flag -g
g++ -g Matrix.cpp -o Matrix
- run debugger command
gdb Matrix
- add breakpoint to the suspect Line
b 43
- run program
r
- trace result.data variable
1- std::vector of length 2, capacity 2 = {std::vector of length 2, capacity 2 = {0, 0}, 
  std::vector of length 2, capacity 2 = {0, 0}}
2- std::vector of length 2, capacity 2 = {std::vector of length 2, capacity 2 = {7, 0}, 
  std::vector of length 2, capacity 2 = {0, 0}}
3- $4 = std::vector of length 2, capacity 2 = {std::vector of length 2, capacity 2 = {18, 0}, 
  std::vector of length 2, capacity 2 = {0, 0}}

  
*From tracing we notice results.data[0][0] change from 7 (1 x 7) to 18 (2x9) instead of adding cumulative
- bug fixing
43    result.data[i][j] += data[i][k] * other.data[k][j]; //adding + solve it
- recompile and run again
g++  Matrix.cpp -o Matrix
./Matrix
//output
Matrix 1:
1 2 3 
4 5 6 
Matrix 2:
7 8 
9 10 
11 12 
Result of multiplication:
58 64 
139 154 

About

how to debug using gdp

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages