Saturday, September 10, 2011

[Arduino] Light-detected Alarm

This is one of Arduino practice project from "Beginning Arduino, Michael McRoberts". In this exercise, I use an arduino uno board to control a light-detective alarm.


Monday, September 5, 2011

[C++] Storage duration, Scope, and Linkage

Quoted from "C++ Primer Plus, Fifth edition":


C++ uses three separate schemes for storing data, and the schemes differ in how long they preserve data in memory:
• Automatic storage duration—Variables declared inside a function definition—including
function parameters—have automatic storage duration. They are created when program
execution enters the function or block in which they are defined, and the memory
used for them is freed when execution leaves the function or block. C++ has two kinds
of automatic storage duration variables. (Automatic and register)

• Static storage duration—Variables defined outside a function definition or else by
using the keyword static have static storage duration. They persist for the entire time a
program is running. C++ has three kinds of static storage duration variables.
(external, internal, and no linkage)

• Dynamic storage duration—Memory allocated by the new operator persists until it is
freed with the delete operator or until the program ends, whichever comes first. This
memory has dynamic storage duration and sometimes is termed the free store.




[C++] Declare a external (global) variable in header file

If you declare a global variable (in order to share within multifile program) in header file such as:
 int tom = 3;    // declare in header file
It would be wrong, because variable will redefine in multiple c files when you include header file in them.
The right way is use extern keyword that let compile know it is a global variable:

[C++] Escape Sequence Codes

This is part of content of "C++ Primer Plus, Fifth edition" about Escape Codes:



Sunday, September 4, 2011

[C++]Head file management #ifndef, #endif

quoted from "C++ Primer Plus, Fifth edition" about #ifndef, #endif:


You should include a header file just once in a file. There’s a standard C/C++ technique for
avoiding multiple inclusions of header files. It’s based on the preprocessor #ifndef (for if not
defined) directive. A code segment like

#ifndef COORDIN_H_
...
#endif


Fork me on GitHub