Code Examples
Makefile
The following examples require GNU make, which is make
on Linux.
String to Integer
The C++
intmax_t convert( const char * str );
correctly handles erroneous string-to-integer conversions.
#include <iostream> #include <string> using namespace std; int main() { try { intmax_t i = convert( "123" ); cout << i << endl; i = convert( "123ABC" ); cout << i << endl; } catch( invalid_argument ) { cout << "invalid integer" << endl; } } 123 invalid integer
The convert routine correctly handles string-to-integer conversions and is directly accessible in μC++ programs, but must be copied into C++ programs.
C++
- Stream I/O: without exceptions (IO.cc) and with exceptions (IOexp.cc)
-
string class
- sample program (string.cc) with test data StringTest illustrating a number of string operations
- doubly-linked list template in three versions
- map example (Map.cc)
μC++
- Stream I/O: with exceptions (uIO.cc)
- Full coroutine example using the producer-consumer problem (FullProdCons.cc)
-
Uses the full coroutine producer consumer code to show how to divide classes
into header and implementation files.
- Header file for the consumer full coroutine (Cons.h)
- Implementation of the consumer full coroutine (Cons.cc)
- Header file for the producer full coroutine (Prod.h)
- Implementation of the producer full coroutine (Prod.cc)
- Driver for the program (ProdConsDriver.cc)
- Using uQueue (uQueue.cc)
- Using uSequence (uSequence.cc)
- Using exceptions
- Coroutine example (uCoroutine.cc)
- Example with one file (uException.cc)
- Same code, split across multiple header and implementation files:
- Basic Administrator (Admin.cc)
C∀
- Stream I/O: with exceptions (CFAIO.cfa)
Barging Checker
The following macros are used to check for barging with locks/monitors that allow calling and signalled tasks to compete for the lock.