How to report bugs effectively [www.chiark.greenend.org.uk/~sgtatham]
This essay is a classic ! I did not bookmark it last time I had read it, it's worth to have it always by hand.
I should probably inspire myself and write something similar for our community. A user shares frequently details in a manner: "It does not work, please help me."
No platform, compiler or the line of code or at least function where it crashed or surprisingly returns an unexpected value.
May 10, 2013
May 5, 2013
The Practice of Programming (book review)
I don't need to introduce authors Brian W. Kernighan or Rob Pike. The authors were one of the reasons why I bought this book. It was published in 1999. Although it's a bit dated, but still relevant to this day. The book consists of 8 chapters. Each chapter is divided into suchapters and many have small paragraphs with different focuses. I'll keep it short not to spoil the book.
2. chapter - Algorithms and Data Structures
1. chapter - Style
key words: names , style consistency, macros, magic numbers, comments.
Be consistent in your code, use indent to show structure, use descriptive names for globals, don't leave comment for obvious code.
Be consistent in your code, use indent to show structure, use descriptive names for globals, don't leave comment for obvious code.
key words: searching - linear , binary searching, sorting - Quicksort, O-notation, Trees, Hash tables, Lists
This chapter serves as an introduction to a searching, a sorting and data structures.
3. chapter - Design and Implementation
key words: markov chain algorithm
4. chapter - Interfaces
Implementation of markov chain algorithm in C, C++, Java, Awk and Perl. They measure performance and show differences in the implementations.
key words: comma separated values
An implementation of CVS library in C and C++. What is discussed in this chapter : How to create an interface, error handling, resource management, implementation details.
5. chapter - Debugging
5. chapter - Debugging
key words: bug, debugger, tracing
How to solve a bug, don't make the same mistake twice, stack trace and many more tips.
6. chapter - Testing
key words: white box testing, black box testing, scaffolds
Test bondaries, pre/post conditions, error returns, test scaffold, test coverage.
7. chapter - Performance
key words: efficiency, profiling
They used spam filter as an example to show how to improve performance. Few versions of spam filter is presented with their performance issues. There are advices how to tune the code.
8. chapter - Portability
key words: standard, undefined behavior, C libraries
Typical problems are presented like signess of char, byte order, shifts, bitfields and many more.
9. chapter - Notation
key words: regular expressions
key words: regular expressions
How data are formatted (an example of creating a packet for sending). Regular expressions with grep, awk, tcl and perl examples.
One addition which is from the last year from Rob Pike: http://www.informit.com/articles/article.aspx?p=1941206 .
Thinking debugging is much more powerful than line-by-line debugging. I tend most of times to think first before I debug but I need more experience to do it quick and right the first time.
What I enjoyed, was real examples from their experience or others.
References:
April 29, 2013
Casting in C++
As I most of my day time code in C, I used C-style casts in the beginning. The application was mixture of C and C++ (C++ API for C static library), therefore casts were needed (void pointer to data returned).
I corrected entire code, to replace with proper C++ casts. Because be aware of how C casts are interpreted in C++ language, they combine const_cast, static_cast and reinterpret_cast. One which works is used. Here are some disadvantages: hard to locate them, no compiler check, the ambiguity => not explicit, no dynamic runtime check (sometimes useful but costy - RTTI).
There are 4 casting operators in C++: static_cast, const_cast, dynamic_cast, reinterpret_cast.
Small guide to casting in C++ [justcheckingonall.wordpress.com]
It gives an insight about C++ casting,
I corrected entire code, to replace with proper C++ casts. Because be aware of how C casts are interpreted in C++ language, they combine const_cast, static_cast and reinterpret_cast. One which works is used. Here are some disadvantages: hard to locate them, no compiler check, the ambiguity => not explicit, no dynamic runtime check (sometimes useful but costy - RTTI).
There are 4 casting operators in C++: static_cast, const_cast, dynamic_cast, reinterpret_cast.
Small guide to casting in C++ [justcheckingonall.wordpress.com]
It gives an insight about C++ casting,
April 22, 2013
Two sites with list of C / ARM / AVR books and tutorials.
While I was checking books which I would like to buy, I found these two webpages which share literature about C/embedded/signals.
Keil embedded bookshelf [keil.com/books]
I had to ordered another two new books which I have not read yet, ARM assembly language and ARM system developer's guide. I can't wait to read them.
AVR freaks - Online C books and Tools [avrfreaks.net]
Rich list of many tutorials, books mostly for C lang, AVR related.
Keil embedded bookshelf [keil.com/books]
I had to ordered another two new books which I have not read yet, ARM assembly language and ARM system developer's guide. I can't wait to read them.
AVR freaks - Online C books and Tools [avrfreaks.net]
Rich list of many tutorials, books mostly for C lang, AVR related.
April 20, 2013
G++ and C static library with C files ( -x flag )
I faced one rather small problem which engaged me for a while. I ported C++ demo application to CodeWarrior 10.3 using g++. Linked library was compiled with gcc.
Linker was against me to build the demo. It shown undefined variable errors in static library (library plus some files which are outside of the library). I knew those undefined variables are properly declared and had to be visible to the linker. The output in a console was allright at first sight.
I explored linker settings in CW (not much to do with options there, preferably to use own linker commands). Did not do the trick. I proceeded to compiler, here's link which made it clear:
man gcc [cf.ccmr.cornell.edu/cgi-bin]
Particulary option -x none. I did not see any -x in the console output. Once I had added it into command line pattern, it linked.
"${ARMSourceryDir}/${COMMAND}" -x none ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}
Linker was against me to build the demo. It shown undefined variable errors in static library (library plus some files which are outside of the library). I knew those undefined variables are properly declared and had to be visible to the linker. The output in a console was allright at first sight.
I explored linker settings in CW (not much to do with options there, preferably to use own linker commands). Did not do the trick. I proceeded to compiler, here's link which made it clear:
man gcc [cf.ccmr.cornell.edu/cgi-bin]
Particulary option -x none. I did not see any -x in the console output. Once I had added it into command line pattern, it linked.
"${ARMSourceryDir}/${COMMAND}" -x none ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}
April 13, 2013
Sublime Go to the definition - CTags
One of the two features I really appreciate during a development - Go to the definition. I had downloaded Ctags plugin but it did not work out of the box only because I did not know about downloading CTags (http://ctags.sourceforge.net).
Once you extract files, add a path to CTags in PATH inside Enviroment variables (for instance ;C:/Program Files/ctags). Open command line and type ctags. If an output is ctags: No files specified, we can proceed to the Sublime.
Click on any project opened in file browser there, first option should be CTags Rebuild tags. CTags creates two files in your project .tags_sorted_by_file and .tags. Use shortcut to GO TO THE DEFINITION is by default CTRL+SHIFT+. in windows. Awesome!
Once you extract files, add a path to CTags in PATH inside Enviroment variables (for instance ;C:/Program Files/ctags). Open command line and type ctags. If an output is ctags: No files specified, we can proceed to the Sublime.
Click on any project opened in file browser there, first option should be CTags Rebuild tags. CTags creates two files in your project .tags_sorted_by_file and .tags. Use shortcut to GO TO THE DEFINITION is by default CTRL+SHIFT+. in windows. Awesome!
April 10, 2013
Compile time assertion in C lang
I planned to check more information about compilation assertion in C. How to check for size errors, alignments during compilation phase? The answer is compilation assertion which declares a variable which causes compilation error if the condition is true. Here are "simplest" one:
Checking sizeof at compile time [scaryreasoner.wordpress.com]
This article provides explanation of BUILD_BUG_ON macro which is used in linux for example. It can't be used in global scope because it's a statement.
Catching errors early with compile-time assertions [embedded.com]
Dan Saks article which solves the global scope problem with previous one,
Even though message is not shown in some IDEs, at least code line is thus it's easy to decipher it from the msg parameter why it caused an error.
Checking sizeof at compile time [scaryreasoner.wordpress.com]
This article provides explanation of BUILD_BUG_ON macro which is used in linux for example. It can't be used in global scope because it's a statement.
Catching errors early with compile-time assertions [embedded.com]
Dan Saks article which solves the global scope problem with previous one,
#define compile_time_assert(cond, msg) \ typedef char msg[(cond) ? 1 : -1]
Even though message is not shown in some IDEs, at least code line is thus it's easy to decipher it from the msg parameter why it caused an error.
April 2, 2013
Header circular problem ("impossible" errors received)
Once I moved only one include from the main code file to the main header file, I received weird errors from IAR:
Error[Pe020]: identifier "namespace" is undefinied
Error[Pe065]: expected a ";"
and so on...
My intuition was that it is header include problems. How could it scream namespace is undefined.
I corrected few includes in my application but still no success. The same application was successfully built in KEIL. I continued with removal all unnecessary includes until I found the one which caused all errors.
Lesson learned, time to do a review of our includes in all applications.
Error[Pe020]: identifier "namespace" is undefinied
Error[Pe065]: expected a ";"
and so on...
My intuition was that it is header include problems. How could it scream namespace is undefined.
I corrected few includes in my application but still no success. The same application was successfully built in KEIL. I continued with removal all unnecessary includes until I found the one which caused all errors.
Lesson learned, time to do a review of our includes in all applications.
Subscribe to:
Posts (Atom)