how to read source code?

B

becker

Hi, I am learning some code reading techniques for source codes written
in C or C++. Could anybody give me any suggestions on how I can learn
those techniques? Any book suggestions or info about good tutorials on
web sites are appriciated. Thanks a lot in advance.
 
M

Malcolm

becker said:
Hi, I am learning some code reading techniques for source codes written
in C or C++. Could anybody give me any suggestions on how I can learn
those techniques? Any book suggestions or info about good tutorials on
web sites are appriciated. Thanks a lot in advance.
C can be very difficult to read, because the language makes it easy to write
what I call compileable gibberish.

The main rule is that a compiler is much better at picking up syntax errors
than a human. So don't expect to spot every missing semicolon. Unfortunately
there are a few gotchas, e.g.

for(i=0;i<len;i++);
str = 'x';

will compile cleanly and then produce a very strange bug as your string is
extended, probably with garbage characters, and not set all xes at all.

However most programmers are not pathological. Usually code is broken fairly
logically into functions, and each function does a defined task. If you can
work out what the function does, and what the parameters are, then it
doesn't usually matter too much if you cannot follow the code. Most of the
time the algorithm will be very striaghtforward and you can write code to do
the same thing easily.

A few functions will be the heart of the program, and may be difficult.
However here your problem transcends computer language. If you don't
understand the mathematics of a fast Fourier transform, for instance, then
you will have to learn somehow. It will be very difficult to reverse
engineer someone else's FFT() function and understand it that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top