Giter Club home page Giter Club logo

debugging_cpp's Introduction

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 

debugging_cpp's People

Contributors

hasv07 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.