MRW C++ Library Reference Manual

Size: px
Start display at page:

Download "MRW C++ Library Reference Manual"

Transcription

1 MRW C++ Library Reference Manual Version Generated by Doxygen Mon Aug 20 21:44:

2 CONTENTS 1 Contents 1 MRW C++ Library Main Page 1 2 MRW C++ Library Module Index 2 3 MRW C++ Library Namespace Index 3 4 MRW C++ Library Hierarchical Index 3 5 MRW C++ Library Class Index 5 6 MRW C++ Library File Index 8 7 MRW C++ Library Page Index 9 8 MRW C++ Library Module Documentation 10 9 MRW C++ Library Namespace Documentation MRW C++ Library Class Documentation MRW C++ Library File Documentation MRW C++ Library Example Documentation MRW C++ Library Page Documentation MRW C++ Library Main Page The official homepage is on: The minimal runtime package (for use with VideoreKorder): Minimalpaket (für den VideoreKorder): mrw-c++-minimal i586.rpm More downloads see Download and Installation of the MRW-C++ Library. All features are listed on the "Modules" page.

3 1.1 Introduction Introduction Featureful C++ Library containing a lot of needful things. Everything, I often need, but it s missing in C++ standard libraries and other common 3rd party libraries, such as log4cxx, cppunit and boost. I have paid attention to define simple and a nice to use interfaces. The library makes use of object orientation, operator overload and templates, where it makes sense. The library passes several module tests before each delivery. It is therefore stable and tested. 1.2 Supported Platforms The library is generic UNIX, but should also work on Windows. It is sporadically tested on Windows in Cygwin. Stack trace works on Linux only, it could theoretically work on Sun Solaris too, but this is untested. Stack trace without symbol resolution, just getting the raw addresses, only depends on GNU gcc and should work on all platforms. Feedback is welcome! 1.3 Missing a Feature, Found a Bug? You are missing a feature, or an implementation is too incomplete for the purpose you need it? Or you even found a bug? Just ask me and I ll try to help you! My address is in the file AUTHORS and on my website: Additional Information See the "Related Pages". Download and Installation of the MRW-C++ Library Readme Usage of the Library: Include and Link Thread Safety Library Versioning License Installation News Change Log

4 2 MRW C++ Library Module Index 3 2 MRW C++ Library Module Index 2.1 MRW C++ Library Modules Here is a list of all modules: C++ Evaluation of Command Line Arguments 10 Classes for Automated Resource Handling 11 Configuration File Handler 21 Dynamic Library Loading (ltdl) 25 Execute UNIX Commands 30 File and System Utilities 31 Regular Expressions 44 Regular Expressions 45 Tokenizer 68 Debug Utilities 47 Function Tracing (using log4cxx) 31 Automatic Function Trace for GNU g++ 14 Automatic Function Trace to standard out for GNU g++ 16 Automatically initialize log4cxx 38 Collect and Format a Stack Trace 47 Automated Unexpected and Terminate Handler 16 Exceptions with Stack Trace 26 Suggested Exception Handling Rules 29 Extensions for C++ Standard Libraries 52 STL extensions 36 deque 24 list 36 map 39 multimap 41

5 3 MRW C++ Library Namespace Index 4 multiset 43 set 45 vector 68 Useful Global Functions 50 String extensions 54 3 MRW C++ Library Namespace Index 3.1 MRW C++ Library Namespace List Here is a list of all documented namespaces with brief descriptions: mrw (Namespace for this library ) 70 4 MRW C++ Library Hierarchical Index 4.1 MRW C++ Library Class Hierarchy This inheritance list is sorted roughly, but not completely, alphabetically: mrw::args 74 mrw::auto< T > 82 mrw::autoptr< T > 82 mrw::autoptrary< T > 84 mrw::autoresource< RESOURCE_TYPE, FUNCTION_PTR, FREE_- FUNCTION, INITIAL_VALUE_TYPE, INITIAL_VALUE, FREE_- TYPE > 87 mrw::cmd 91 mrw::configfilereader 95 mrw::configfilewriter 100 mrw::configfilereader::value 98 mrw::dir 102 mrw::dir::entry 104 mrw::dynamiclibrary 106

6 4.1 MRW C++ Library Class Hierarchy 5 mrw::errno 112 mrw::exec 114 mrw::partialexec 133 mrw::file 120 mrw::fntrace 123 mrw::mmaphandle 125 mrw::opt 125 mrw::param 129 mrw::param::value 131 mrw::pipe 138 mrw::pointercounter 140 mrw::regexp 141 mrw::smartpointerparent 146 mrw::smartpointer< TYPE > 144 mrw::stacktrace 146 mrw::stacktrace::codepos 150 exception mrw::exception 112 mrw::bad_alloc 89 mrw::bad_cast 90 mrw::bad_exception 90 mrw::bad_typeid 91 mrw::executionfailedexc 119 mrw::logic_error 124 mrw::domain_error 105 mrw::invalid_argument 123 mrw::length_error 124 mrw::out_of_range 128

7 5 MRW C++ Library Class Index 6 mrw::runtime_error 144 mrw::dynamiclibrary::failure 111 mrw::overflow_error 128 mrw::range_error 141 mrw::underflow_error 154 mrw::unix_error 154 mrw::tokenizer MRW C++ Library Class Index 5.1 MRW C++ Library Class List Here are the classes, structs, unions and interfaces with brief descriptions: mrw::args (Handle command line arguments ) 74 mrw::auto< T > (Automatically calls free for malloc allocated memory. Instanciate it as mrw::auto<type >::Free ) 82 mrw::autoptr< T > (Automatically deletes a pointer when destructed ) 82 mrw::autoptrary< T > (Automatically deletes an array pointer when destructed ) 84 mrw::autoresource< RESOURCE_TYPE, FUNCTION_PTR, FREE_- FUNCTION, INITIAL_VALUE_TYPE, INITIAL_VALUE, FREE_- TYPE > (Automatically frees a resource when destructed ) 87 mrw::bad_alloc (Replacement for std::bad_alloc, but with stack trace ) 89 mrw::bad_cast (Replacement for std::bad_cast, but with stack trace ) 90 mrw::bad_exception (Replacement for std::bad_exception, but with stack trace ) 90 mrw::bad_typeid (Replacement for std::bad_typeid, but with stack trace ) 91 mrw::cmd (A system command to be executed ) 91 mrw::configfilereader (Parse configuration file and access the contents ) 95 mrw::configfilereader::value (A configuration file value ) 98

8 5.1 MRW C++ Library Class List 7 mrw::configfilewriter (Parse configuration file and offer read / write access to the contents ) 100 mrw::dir (Directory access ) 102 mrw::dir::entry (Directory entry ) 104 mrw::domain_error (Replacement for std::domain_error, but with stack trace ) 105 mrw::dynamiclibrary (Dynamic Library loaded from the filesystem at runtime ) 106 mrw::dynamiclibrary::failure (Failure in access to shared libraries ) 111 mrw::errno (Stores a UNIX errno error number and converts it to string )112 mrw::exception (Replacement for std::exception, that collects a stack trace ) 112 mrw::exec (Execute a command in a new process ) 114 mrw::executionfailedexc (Exception: Execution of command failed ) 119 mrw::file (File handling utilities ) 120 mrw::fntrace 123 mrw::invalid_argument (Replacement for std::invalid_argument, but with stack trace ) 123 mrw::length_error (Replacement for std::length_error, but with stack trace ) 124 mrw::logic_error (Replacement for std::logic_error, but with stack trace ) 124 mrw::mmaphandle (Resource handle for mmap ) 125 mrw::opt (This class represents one command line option ) 125 mrw::out_of_range (Replacement for std::out_of_range, but with stack trace ) 128 mrw::overflow_error (Replacement for std::overflow_error, but with stack trace ) 128 mrw::param (List of additional (mandatory) parameter to one command line argument ) 129 mrw::param::value (Abstract base class to represent one single parameter value ) 131

9 6 MRW C++ Library File Index 8 mrw::partialexec (Execute a UNIX program in non blocking parts ) 133 mrw::pipe (Class that implements an unnamed UNIX pipe ) 138 mrw::pointercounter 140 mrw::range_error (Replacement for std::range_error, but with stack trace ) 141 mrw::regexp (Regular expression ) 141 mrw::runtime_error (Replacement for std::runtime_error, but with stack trace ) 144 mrw::smartpointer< TYPE > (Smart Pointer Implementation ) 144 mrw::smartpointerparent 146 mrw::stacktrace (Store and print a stack trace of the actual position in code ) 146 mrw::stacktrace::codepos (Structure to store all evaluated information )150 mrw::tokenizer (Split strings into parts separated by delimiters ) 151 mrw::underflow_error (Replacement for std::underflow_error, but with stack trace ) 154 mrw::unix_error (To be thrown when a unix system call fails, evaluates errno ) MRW C++ Library File Index 6.1 MRW C++ Library File List Here is a list of all documented files with brief descriptions: mrw/arg.cpp 156 mrw/arg.hpp 157 mrw/auto.hpp 158 mrw/autofunctiontracelog4cxx.cpp 160 mrw/autofunctiontracestdlog.cpp 161 mrw/autostacktracelog4cxx.cpp 162 mrw/autostacktracestderr.cpp 163

10 6.1 MRW C++ Library File List 9 mrw/configfile.cpp 163 mrw/configfile.hpp 164 mrw/deque.hpp 165 mrw/dynamiclibrary.hpp 166 mrw/errno.cpp 167 mrw/errno.hpp 167 mrw/exception.cpp 169 mrw/exception.hpp 170 mrw/exec.cpp 172 mrw/exec.hpp 174 mrw/file.hpp 175 mrw/functiontrace.cpp 176 mrw/functiontrace.hpp 177 mrw/list.hpp 178 mrw/log4cxxconfiguration.cpp 179 mrw/map.hpp 180 mrw/mrw.hpp?? mrw/multimap.hpp 180 mrw/multiset.hpp 181 mrw/regexp.cpp 182 mrw/regexp.hpp 183 mrw/set.hpp 184 mrw/smartpointer.hpp 185 mrw/stacktrace.cpp 185 mrw/stacktrace.hpp 186 mrw/stdext.cpp 187 mrw/stdext.hpp 188

11 7 MRW C++ Library Page Index 10 mrw/string.hpp 189 mrw/tokenizer.hpp 192 mrw/unistd.hpp 192 mrw/vector.hpp 194 mrw/version.cpp MRW C++ Library Page Index 7.1 MRW C++ Library Related Pages Here is a list of all related documentation pages: Download and Installation of the MRW-C++ Library 197 Usage of the Library: Include and Link 199 Thread Safety 199 Library Versioning 200 License 200 Readme 209 Installation 210 News 213 Change Log 215 Todo List MRW C++ Library Module Documentation 8.1 C++ Evaluation of Command Line Arguments Detailed Description These classes do simple and easy command line argment evaluation in C++. Features: every argument has a long and a short option all arguments are optional and provide a default value

12 8.1 C++ Evaluation of Command Line Arguments 11 the order of options is not important every option can take any (fixed) number of additional parameter of type string integer boolean ("yes", "on", "true" evaluates to true) short options can be combined, instead of -a -b -c 15 you can simply write -abc 15 automated help display (support for option -h) mrw::args is the main user interface class that represents all command line options with their arguments. It is implemented as singleton, so the same instance can be accessed from everywhere in the code. It mst be setup just in the beginning of the main() function. The other important class for the end user is mrw::opt, one possible option with additional parameter. The end user needs mrw::opt to setup all allowed command line options in the beginning, bevore evaluation of the user given command line is done (before argc and argv is shifted into mrw::args. The third class a user should know is mrw::param. It represents the arguments to one option. Every instance of mrw::opt owns one instance of mrw::param that is either empty or list of (mandatory) arguments of type std::string, int or bool. The classes are normally used this way: // this program may be called e.g. with the following arguments: //./a.out --coordinates vo out.txt -n MyName int main(int argv, char const*const*const argv) { try { mrw::args::instance() // setup the possible options <<mrw::opt( h, "--help", "Show this help text") <<mrw::opt( v, "--verbose", "print more information") <<mrw::opt( q, "--quiet", "be quiet") <<mrw::opt( n, "--name", mrw::param()<<"mrw", "name of the user") <<mrw::opt( o, "--output-file", mrw::param()<<"", "file to load") <<mrw::opt( c, "--coordinates", mrw::param()<<0<<0, "X, Y coordinate") // set a description text for help <<"This is a testprogram for argument evaluation in C++" // define the help option << h // shift in the command line arguments <<argc<<argv;... // example usage of simple option if (mrw::args::instance().find( v )) // be verbose here if (mrw::args::have( v )) // the same, simpler: be verbose here... // example usage of option with one parameter ifstream file(mrw::args::tostring( o ).c_str());... // example usage of option with two parameter int x = mrw::args::instance().find( c )[0]->toInt(); // first integer int y = mrw::args::toint( c, 1); // second; alternative, simpler access

13 8.2 Classes for Automated Resource Handling 12 }... return 0 } } catch (mrw::exception& x) { // trace error, print help or mention option -h } Classes class mrw::param List of additional (mandatory) parameter to one command line argument. class mrw::opt this class represents one command line option class mrw::args handle command line arguments 8.2 Classes for Automated Resource Handling Detailed Description For pointers that have been allocated with new, you can use std::auto_ptr to automatically free them when you leave the context. Unfortunately there is no such thing for malloc (except malloca that only works for a subset of problems: if you and not a system call allocates memory), open and so on. These classes can take over the resource ownership. The following ressource handler are predefined: mrw::autoptr<> is the same as std::auto_ptr, but can be stored in STL containers mrw::autoptr<classname> xyz(new ClassName(a, b, c)); mrw::mmaphandle frees an mmap handle with munmap mrw::auto<>::free frees malloc allocated memory with free mrw::auto<char*>::free xxx((char*)malloc(15)); mrw::smartpointer<> is a shared pointer that deletes memory when all owners have died mrw::smartpointer<classname> xyz(new ClassName(a, b, c)); mrw::pipe handles UNIX pipes and closes them on exit

14 8.2 Classes for Automated Resource Handling 13 mrw::autofile automatically closes open files mrw::automapper calls munmap on memory mapped files mrw::autobfd automatically calls bfd_close If this is not enough, you can typedef your own ressource handler from the template class mrw::autoresource<>. For example, mrw::autofile is defined as: typedef mrw::autoresource<int, int(*)(int), &close, int, -1> mrw::autofile; Classes class mrw::autoresource< RESOURCE_TYPE, FUNCTION_PTR, FREE_- FUNCTION, INITIAL_VALUE_TYPE, INITIAL_VALUE, FREE_TYPE > Automatically frees a resource when destructed. class mrw::autoptr< T > Automatically deletes a pointer when destructed. class mrw::autoptrary< T > Automatically deletes an array pointer when destructed. class mrw::mmaphandle Resource handle for mmap. class mrw::auto< T > Automatically calls free for malloc allocated memory. mrw::auto<type >::Free. Instanciate it as class mrw::smartpointer< TYPE > Smart Pointer Implementation. class mrw::pipe class that implements an unnamed UNIX pipe Typedefs typedef mrw::autoresource< int, int( )(int),&close, int,-1 > mrw::autofile Automatically closes a file when destructed. typedef mrw::autoresource< MMapHandle, void( )(MMapHandle &),&mrw::munmap, int > mrw::automapper Automatically calls munmap on destruction for mmaped files.

15 8.2 Classes for Automated Resource Handling 14 typedef mrw::autoresource< bfd, int( )(bfd ),&bfd_close, int > mrw::auto- Bfd Automatically calls bfd_close for bfd. Functions void mrw::munmap (MMapHandle &res) throw (std::bad_exception) Typedef Documentation typedef mrw::autoresource<bfd, int( )(bfd ), &bfd_close, int> mrw::autobfd Automatically calls bfd_close for bfd. Precondition: #include <mrw/auto.hpp> It acts like a std::auto_ptr, but for bfd, that means it calls bfd_close whenever the context is left. Definition at line 401 of file auto.hpp typedef mrw::autoresource<int, int( )(int), &close, int, -1> mrw::autofile Automatically closes a file when destructed. Precondition: #include <mrw/auto.hpp> AutoFile works exactly like std::auto_ptr, but for files instead of pointers. Whenever the context of AutoFile is left, the opened file is close. This way, resources are freed even in case of exceptions. Definition at line 356 of file auto.hpp typedef mrw::autoresource<mmaphandle, void( )(MMapHandle&), &mrw::munmap, int> mrw::automapper Automatically calls munmap on destruction for mmaped files. Precondition: #include <mrw/auto.hpp> It s the same as std::auto_ptr, but for mmap instead of new. When the context of AutoMapper is left, munmap is called. Definition at line 393 of file auto.hpp.

16 8.3 Automatic Function Trace for GNU g Automatic Function Trace for GNU g++ Collaboration diagram for Automatic Function Trace for GNU g++: Funct i on Tr aci ng ( usi ng l og4cxx) Aut omat i c Funct i on Tr ace f or GNU g Detailed Description If you compile your program with GNU g++ / gcc, and you want to add function tracing without changing a single line of your code, here s the solution: If you link to the library libmrwautofunctiontracelog4cxx using a linker option such as: -lmrwautofunctiontracelog4cxx and you must enable the GNU Compiler Collection specific function trace feature with compile and link option -finstrument-functions then you get an automatical function trace, that traces to level DEBUG using the log4cxx library. You don t need to change a single line in your code! This feature depends on: the GNU C++ compiler gcc mrw::stacktrace log4cxx optional: boost for thread support The logger hiararchy name is: "mrw.fn.<full-method-name>" where <full-method-name> is the full name of the method, including namespace and class name, seperated not by double colon :: but by single dots. as it is common use in log4cxx. This way, you can enable or disable the function trace per namespace, per class or even per method. The function trace does not start, before the program main is reached! Only the calls within the main are traced, but not during the initialisation and destruction of static members. This is necessary, because otherwise access the incompletely initialized MRW-C++ library itself may cause a crash. A good default configuration is given in Automatically initialize log4cxx. Depending on your log4cxx configuration, a function trace may look e.g. like this (very simple configuration with very few additional information): mrw.fn.anotherfunction mrw.fn.hallowelt.fn1 mrw.fn.hallowelt.fn mrw.fn.hallowelt.a.method mrw.fn.hallowelt.a.method mrw.fn.hallowelt.a.method mrw.fn.hallowelt.a.method mrw.fn.hallowelt.fn mrw.fn.hallowelt.fn \ anotherfunction() \ HalloWelt::fn1() \ HalloWelt::fn() \ HalloWelt::A::method() / HalloWelt::A::method() \ HalloWelt::A::method() / HalloWelt::A::method() / HalloWelt::fn() \ HalloWelt::fn()

17 8.4 Automatic Function Trace to standard out for GNU g++ 16 mrw.fn.hallowelt.a.method mrw.fn.hallowelt.a.method mrw.fn.hallowelt.a.method mrw.fn.hallowelt.a.method mrw.fn.hallowelt.fn mrw.fn.hallowelt.fn1 mrw.fn.anotherfunction \ HalloWelt::A::method() / HalloWelt::A::method() \ HalloWelt::A::method() / HalloWelt::A::method() / HalloWelt::fn() / HalloWelt::fn1() / anotherfunction() Note: The configurator is not installed automatically. If you want to trace e.g. on the console, you have to call log4cxx::basicconfigurator::configure(); as first statement in your main(). See also: Automatically initialize log4cxx if you also want to automatically configure log4cxx Multithreading Multithreading is also supported, then you need to link to the thread safe compilat of the library libmrwautofunctiontracelog4cxx-mt with option -libmrwautofunctiontracelog4cxx-mt and you need the option -pthread in addition to -finstrument-functions which is still required. Thread support requires the boost thread library. See for details. Functions void cyg_profile_func_enter (void, void ) attribute ((no_instrument_- function)) void cyg_profile_func_exit (void, void ) attribute ((no_instrument_- function)) 8.4 Automatic Function Trace to standard out for GNU g++ Collaboration diagram for Automatic Function Trace to standard out for GNU g++: Funct i on Tr aci ng ( usi ng l og4cxx) Aut omat i c Funct i on Tr ace t o st andar d out f or GNU g++ Same as Automatic Function Trace for GNU g++, but traces to stdlog. If you link to the library libmrwautofunctiontracestdlog using a linker option such as: -lmrwautofunctiontracestdlog and you must enable the GNU Compiler Collection specific function trace feature with compile and link option -finstrument-functions then you get an automatical function trace, that traces to stdlog. You don t need to change a single line in your code!

18 8.5 Automated Unexpected and Terminate Handler Automated Unexpected and Terminate Handler Collaboration diagram for Automated Unexpected and Terminate Handler: Col l ect and Format a St ack Trace Aut omat ed Unexpect ed and Ter mi nat e Handl er Detailed Description Don t care about the unexpected handler, don t care about a try-catch in the main, let the library do all the repetitive work for you. with Stack Trace For all your programs it is recommended to implement an identical unexpected handler, that rethrows, catches the mrw::exception, std::exception and all unknown exceptions, traces them and finally quits with a throw of a std::bad_exception. You are also required to write a try catch block around all in your main, so that you don t miss any exception. The only thing that may be different from project to project is, how tracing is done. The MRW C++ Class Library provides you with additional libraries you can link to. By linking to the library, you get an unexpected handler and an exception trace in the main for free: You don t need to add a single line of code, just link to one more library! The libraries differ in how tracing is done. The Implementation is done with a static instance of a class that sets the unexpected handler in the constructor Trace using std::cerr If you link to the library libmrwexcstderr using a linker option such as: -lmrwexcstderr, then an unexpected and a terminate handler are registered, that trace to the standard error stream std::cerr. Also for all know signals there s a signal handler to trace the stack before termination (except in case of a SIGTRAP, wehere the program is not terminated). You don t need to change a single line in your code! Trace using the log4cxx Library If you link to the library libmrwexclog4cxx using a linker option such as: -lmrwexclog4cxx, then an unexpected and a terminate handler are registered, that trace a fatal error using the log4cxx library. Also for all know signals there s a signal handler to trace the stack before termination (except in case of a SIGTRAP, wehere the program is not terminated). You don t need to change a single line in your code! The log4cxx library is located at: Note: The configurator is not installed automatically. If you want to trace e.g. on the con-

19 8.5 Automated Unexpected and Terminate Handler 18 sole, you have to call log4cxx::basicconfigurator::configure(); as first statement in your main(). See also: Automatically initialize log4cxx if you also want to automatically configure log4cxx. Functions void mrw::unexpected_log4cxx () unexpected handler, that traces using log4cxx void mrw::terminate_log4cxx () terminate handler, that traces using log4cxx void mrw::signal_log4cxx (int sig) segmentation-fault handler, that traces using log4cxx void mrw::unexpected_stderr () unexpected handler, that traces to std::cerr void mrw::terminate_stderr () terminate handler, that traces to std::cerr void mrw::signal_stderr (int sig) segmentation-fault handler, that traces using stderr Function Documentation void mrw::signal_log4cxx (int sig) segmentation-fault handler, that traces using log4cxx The segmentation-fault handler is installed automatically when you link to -lmrwexclog4cxx. The implementation of this handler is as follows: void signal_log4cxx(int sig) { std::string txt; bool abort(true); switch sig { case SIGFPE: txt="sigfpe: Arithmetic error."; break; case SIGILL: txt="sigill: Illegal instruction."; break; case SIGSEGV: txt="sigsegv: Segmentation fault" " (invalid access to valid memory)."; break; case SIGBUS: txt="sigbus: Invalid pointer dereference" " (access to an invalid memory address)."; break; case SIGABRT: txt="sigabrt: Funktion abort was called."; break; case SIGIOT: txt="sigiot: PDP-11 iot instruction"; break; case SIGTRAP: txt="sigtrap: Breakpoint instruction."; abort=false; break;

20 8.5 Automated Unexpected and Terminate Handler 19 } case SIGEMT: txt="sigemt: Emulator trap."; break; case SIGSYS: txt="sigsys: Bad system call."; break; default: txt="unknown Signal Nr. "+sig; break; } StackTrace::createSymtable(); std::string st((std::string)stacktrace()); log4cxx::loggerptr logger(log4cxx::logger::getlogger("mrw.stacktrace")); logger->fatal("aborted by signal: "+txt+"\nstack:\n"+st); if (abort) exit(1); Definition at line 206 of file autostacktracelog4cxx.cpp. References mrw::stacktrace::createsymtable(), and mrw::string() void mrw::signal_stderr (int sig) segmentation-fault handler, that traces using stderr The segmentation-fault handler is installed automatically when you link to -lmrwexcstderr. The implementation of this handler is as follows: void signal_stderr(int sig) { std::cerr<<"signal RECEIVED: "<<std::endl; std::string txt; bool abort(true); switch (sig) { case SIGFPE: txt="sigfpe: Arithmetic error."; break; case SIGILL: txt="sigill: Illegal instruction."; break; case SIGSEGV: txt="sigsegv: Segmentation fault" " (invalid access to valid memory)."; break; case SIGBUS: txt="sigbus: Invalid pointer dereference" " (access to an invalid memory address)."; break; case SIGABRT: txt="sigabrt: Funktion abort was called."; break; case SIGTRAP: txt="sigtrap: Breakpoint instruction."; abort=false; break; case SIGSYS: txt="sigsys: Bad system call."; break; default: txt="unknown Signal Nr. "+sig; break; } StackTrace::createSymtable(); std::string st((std::string)stacktrace()); stderr::loggerptr logger(stderr::logger::getlogger(_t("mrw.stacktrace"))); std::cerr<<" Reason:"<<std::endl <<"Aborted by signal: "<<txt<<std::endl <<" Stack:"<<std::endl <<st<<std::endl <<" "<<std::endl; if (abort) exit(1); } Definition at line 204 of file autostacktracestderr.cpp. References mrw::stacktrace::createsymtable(), and mrw::string() void mrw::terminate_log4cxx () terminate handler, that traces using log4cxx

21 8.5 Automated Unexpected and Terminate Handler 20 The terminate handler is installed automatically when you link to -lmrwexclog4cxx. The implementation of this terminate handler is as follows: void terminate_log4cxx() { log4cxx::loggerptr logger(log4cxx::logger::getlogger("mrw.stacktrace")); logger->fatal("uncaught Exception", FILE, LINE ); StackTrace::createSymtable(); std::string st((std::string)stacktrace()); try { throw; exit(0); } catch (const mrw::exception& x) { logger->fatal(std::string("reason:\n")+x.what() +"\nstack:+\n"+x.stacktrace()); } catch (const std::exception& x) { logger->fatal(std::string("reason:\n")+x.what() +"\nstack:\n"+st); } catch (...) { logger->fatal(std::string("reason: **** not available ****") +"\nstack:\n"+st); } exit(1); } Definition at line 148 of file autostacktracelog4cxx.cpp. References mrw::stacktrace::createsymtable(), MRW_LOG4CXX_LOCATION, mrw::exception::stacktrace(), mrw::string(), and mrw::exception::what() void mrw::terminate_stderr () terminate handler, that traces to std::cerr The terminate handler is installed automatically when you link to -lmrwexcstderr. The implementation of this terminate handler is as follows: void terminate_stderr() { std::cerr<<"uncaught EXCEPTION: "<<std::endl; try { throw; } catch (const mrw::exception& x) { StackTrace::createSymtable(); std::cerr<<" Reason:"<<std::endl <<x.what()<<std::endl <<" Stack:"<<std::endl <<x.stacktrace(); } catch (const std::exception& x) { std::cerr<<" Reason:"<<std::endl <<x.what()<<std::endl <<" Stack: **** not available ****"<<std::endl; } catch (...) { std::cerr<<" Reason: **** not available ****"<<std::endl <<" Stack: **** not available ****"<<std::endl; } std::cerr<<" "<<std::endl; exit(1); }

22 8.5 Automated Unexpected and Terminate Handler 21 Definition at line 147 of file autostacktracestderr.cpp. References mrw::stacktrace::createsymtable(), mrw::exception::stacktrace(), and mrw::exception::what() void mrw::unexpected_log4cxx () unexpected handler, that traces using log4cxx The unexpected handler is installed automatically when you link to -lmrwexclog4cxx. The implementation of this unexpected handler is as follows: void unexpected_log4cxx() { log4cxx::loggerptr logger(log4cxx::logger::getlogger("mrw.stacktrace")); logger->fatal("unexpected Exception", FILE, LINE ); StackTrace::createSymtable(); std::string st((std::string)stacktrace()); try { throw; } catch (const mrw::exception& x) { logger->fatal(std::string("reason:\n")+x.what() +"\nstack:+\n"+x.stacktrace()); } catch (const std::exception& x) { logger->fatal(std::string("reason:\n")+x.what() +"\nstack:\n"+st); } catch (...) { logger->fatal(std::string("reason: **** not available ****") +"\nstack:\n"+st); } throw std::bad_exception(); } Definition at line 92 of file autostacktracelog4cxx.cpp. References mrw::stacktrace::createsymtable(), MRW_LOG4CXX_LOCATION, mrw::exception::stacktrace(), mrw::string(), and mrw::exception::what() void mrw::unexpected_stderr () unexpected handler, that traces to std::cerr The unexpected handler is installed automatically when you link to -lmrwexcstderr. The implementation of this unexpected handler is as follows: void unexpected_stderr() { std::cerr<<"unexpected EXCEPTION: "<<std::endl; try { StackTrace::createSymtable(); throw; } catch (const mrw::exception& x) { std::cerr<<" Reason:"<<std::endl <<x.what()<<std::endl <<" Stack:"<<std::endl <<x.stacktrace(); } catch (const std::exception& x) {

23 8.6 Configuration File Handler 22 std::string st((std::string)stacktrace()); std::cerr<<" Reason:"<<std::endl <<x.what()<<std::endl <<" Stack: "<<std::endl<<st; } catch (...) { std::string st((std::string)stacktrace()); std::cerr<<" Reason: **** not available ****"<<std::endl <<" Stack:"<<std::endl<<st; } std::cerr<<" "<<std::endl; throw std::bad_exception(); } Definition at line 92 of file autostacktracestderr.cpp. References mrw::stacktrace::createsymtable(), mrw::exception::stacktrace(), mrw::string(), and mrw::exception::what(). 8.6 Configuration File Handler Detailed Description Precondition: #include <mrw/configfile.hpp> Read configuration parameters from a file Configuration File Syntax Sections: [Section] Syntax (regular expression): \[([ [=#] )\] A configuration file consists of none or more sections. The sections start with tag [Section Name], where Section Name is the name of the section. The default section has an empty name Variables: name = value Syntax (regular expression): [ [\n\t ] ([ [=#\n]]+)[\n\t ] =[\n\t ] ([ [=#]] )[\n\t ] or [ [\n\t ] ([ [=#\n]]+)[\n\t ] =[\n\t ] ("[ "]] ")[\n\t ] or [ [\n\t ] ([ [=#\n]]+)[\n\t ] =[\n\t ] ( [ ]] )[\n\t ] In the section, there are variable definitions in the form of name=value, where name is the name of the variable and value is it s contents. White spaces at the begin or end of the name and the value are stripped. Whitespaces inside a name or value remain unchanged. Please note that a variable name starts at the begoin of line and ends before the equal sign, while the contents starts after the equal sign and ends before the next token starts. If you need a token inside a value, or a variable must start or end with white spaces, you can enclose it in either " or quotes. If a value is quoted and the quoting is not terminated, then the contents is taken up to the end of file. Please note that the same quote must not occur inside the value. All possible tokens are: [, # and =. All other characters are not treated in a special way.

24 8.6 Configuration File Handler Comments: # Comments start with # and end at the end of the line Special Characters \n, [, ], #, =, ", I have chosen a syntax that is downwards compatible with the common Unix configuration file syntax, but with a grammar as loose as possible and with as few restrictions as possible. Special characters have only special meanings in certain contexts. In other contexts, they can be used with no restrictions. The following characters are treated in a special way: [ and ] enclose a section name. A section name may contain any arbitrary character, including new line and white spaces, except a ]. \n (begin of line or file) and = enclose a variable name. In other circumstances (except in comments), a new line has no special meaning. A = inside a value is allowed only if the value is quoted. A variable name may contain any arbitrary character, including white spaces, except a new line or =. = and one out of [, # and the begin of a line that contains = enclose a variable contents if the contents is not quoted. A variable s contents may contain any arbitrary character, including new line and white spaces, except a ], # or the begin of a line that contains =. " or may enclose a variables contents. These characters have only a special meaning, if a variable s contents starts with one of them. Then the variable s contents may contain any arbitrary character, except the same quote itself, which marks the end of the contents. # and \n (end of line or file) enclose a comment. A variable name may contain any arbitrary character, including white spaces, except a new line Restrictions Attention: Due to the actual syntax, it is impossible that a variable s contents contains the following combination: " and and one out of [, = and # If a variable s contents contains heading or trailing white spaces or one out of [, = and #, then it must be quoted either with " or with Example File Nice Example [Section 1] name1 = value1 name2 = value2 [Section 2] name1 = value1 name2 = value2

25 8.7 deque Enhanced Example # this is in the global section, named "" this is a variable name = this is a variable contents [Global] # start of section "Global" multi line text = this is a text that is longer than one line! 1234 = "var=17" # if you need an equal inside a text, enclose it # either in " or in Code Sample try { const char* home(getenv("home")); mrw::configfilereader config(home?home+"/.myprogram":".myprogram"); std::string username(config("user Info", "Name")); } catch (...) { // file read or evaluation error } Classes class mrw::configfilereader Parse configuration file and access the contents. class mrw::configfilewriter Parse configuration file and offer read / write access to the contents. 8.7 deque Collaboration diagram for deque: STL ext ensi ons deque Functions template<typename T, typename A> std::deque< T, A > & operator<< (std::deque< T, A > &l, const T &o) throw (std::bad_exception) push a value to a deque template<typename T, typename A> std::deque< T, A > & operator>> (std::deque< T, A > &l, T &o) throw (std::exception) extract the first value of a deque

26 8.7 deque Function Documentation template<typename T, typename A> std::deque<t, A>& operator<< (std::deque< T, A > & l, const T & o) throw (std::bad_exception) push a value to a deque std::deque<int> test; test<<1<<2<<3<<4<<5<<6<<7<<8; Parameters: l a deque of values o a value to be inserted into deque l Precondition: #include <mrw/deque.hpp> Definition at line 52 of file deque.hpp template<typename T, typename A> std::deque<t, A>& operator>> (std::deque< T, A > & l, T & o) throw (std::exception) extract the first value of a deque std::deque<int> test; test<<1<<2<<3<<4<<5<<6<<7<<8; int i1(0), i2(0), i3(0), i4(0); test>>i1>>i2>>i3>>i4; // now: i1==1 i2==2 i3==3 i4==4 test=={5, 6, 7, 8} Parameters: l a deque of values o a value to be extracted from deque l Exceptions: Note: mrw::length_error,if deque was empty on entry when something is extracted from a deque, it is removed from the deque, that means after every shift the deque is shortened by the shifted element Precondition: #include <mrw/deque.hpp> Definition at line 76 of file deque.hpp. References mrw::string().

27 8.8 Dynamic Library Loading (ltdl) Dynamic Library Loading (ltdl) Detailed Description Implements a C++ wrapper around the Libtool s platform independent dynamic library loading library named libltdl. See info libtool for more information. Loading a symbol from a shared library: void fn() throw(mrw::dynamiclibrary::failure) { static DynamicLibrary lib("libsomething"); static void(*therealfunction)() = (void(*)())lib.symbol("therealfunction"); (*therealfunction)(); // call the loaded function } Precondition: #include <mrw/dynamiclibrary.hpp> Files that use this wrapper must be linked with libltdl, with GNU g++ on UNIX, this is link option: -lltdl Classes class mrw::dynamiclibrary Dynamic Library loaded from the filesystem at runtime. 8.9 Exceptions with Stack Trace Collaboration diagram for Exceptions with Stack Trace: Except i ons wi t h St ack Trace mr w: : except i on Col l ect and Format a St ack Trace Detailed Description The following diagram shows the inheritance of the MRW exception classes and how they are related to the C++ standard exceptions. mrw::exception inherits std::exception, then a inheritance corresponding to the standard is implemented below mrw::exception. To prevent diamond-shaped inheritance, the MRW exceptions below the mrw::exception base class do not inherit from their corresponding standard exception. The exception classes are meant as a replacement to the standard exceptions that provide stack trace information. I suggest exception handling according to Suggested Exception Handling Rules.

28 8.9 Exceptions with Stack Trace 27 std::domain_error std::bad_alloc std::invalid_argument std::bad_cast std::length_error std::logic_error std::out_of_range std::exception std::runtime_error std::overflow_error std::bad_exception std::range_error std::bad_typeid std::underflow_error mrw::domain_error mrw::bad_alloc mrw::invalid_argument mrw::bad_cast mrw::length_error mrw::logic_error mrw::out_of_range mrw::exception mrw::runtime_error mrw::overflow_error mrw::bad_exception mrw::range_error mrw::bad_typeid mrw::underflow_error mrw::unix_error

29 8.9 Exceptions with Stack Trace 28 In addition to the reimplementation of the standard exceptions, There is also a class mrw::errno to handle UNIX C library errno and an exception class mrw::unix_error to that uses mrw::errno to convert errno into a meaningful string and that offers facilities to handle failed UNIX C library calls. Classes class mrw::errno Stores a UNIX errno error number and converts it to string. class mrw::unix_error to be thrown when a unix system call fails, evaluates errno class mrw::exception replacement for std::exception, that collects a stack trace class mrw::bad_alloc Replacement for std::bad_alloc, but with stack trace. class mrw::bad_cast Replacement for std::bad_cast, but with stack trace. class mrw::bad_exception Replacement for std::bad_exception, but with stack trace. class mrw::bad_typeid Replacement for std::bad_typeid, but with stack trace. class mrw::logic_error Replacement for std::logic_error, but with stack trace. class mrw::domain_error Replacement for std::domain_error, but with stack trace. class mrw::invalid_argument Replacement for std::invalid_argument, but with stack trace. class mrw::length_error Replacement for std::length_error, but with stack trace. class mrw::out_of_range Replacement for std::out_of_range, but with stack trace. class mrw::runtime_error Replacement for std::runtime_error, but with stack trace.

30 8.10 Suggested Exception Handling Rules 29 class mrw::overflow_error Replacement for std::overflow_error, but with stack trace. class mrw::range_error Replacement for std::range_error, but with stack trace. class mrw::underflow_error Replacement for std::underflow_error, but with stack trace Suggested Exception Handling Rules Collaboration diagram for Suggested Exception Handling Rules: Col l ect and Format a St ack Trace Suggest ed Except i on Handl i ng Rul es 1. derieve all your exceptions from mrw::exception 2. write exception specifications as follows: (this specification is "binary", it only declares whether an exception is thrown or not, but it does not specify which exact exception can be thrown) if no exception is thrown, specify throw(std::bad_exception) instead of throw() as you would normally specify if any exception is thrown specify throw(std::exception) (Note: If you need a more specific declaration, you must also declare std::bad_exception in addition to your exceptions!) only declare throw() if you are 100% sure, that it is absolutely impossible that this method ever throws an exception, that means this method calls no other function or method (not even from a system library) that does not declare throw() 3. document the exact exception thrown with Doxygen tag 4. write an unexpected handler as follows (or link to a library): void unexpectedhandler() { try { throw; } catch (mrw::exception& x) { // trace x.stacktrace() and x.what() } catch (std::exception& x) { // trace x.what() } catch (...) { // trace unknown unexpected } throw std::bad_exception(); // try to recover }

31 8.11 Execute UNIX Commands 30 What happens: If you throw an exception in a method that declares not to throw an exception, the unexpected handler is called. It writes a stack trace for you to be able to find your bug. Then it throws a std::bad_exception, which is allowed to pass. Your program does not abort, but continues running. If higher in the stack you catch the exception, you may be able to recover. If you throw an exception where you are allowed to, you only need to catch mrw::exception and you can access what() and stacktrace(). For a proof of concept refer to the example exceptionhandling.cpp. The unexpected handler is implemented ready to use in a separate library Execute UNIX Commands Detailed Description There is no easy way to safely execute UNIX commands and to return the output of the callee to the caller. system ist first of all known to be unsafe, because it opens a shell, and second there is no way to transfer the output back to the caller. On the other hand, starting a new process with fork and exec and passing the output of the callee to the caller using pipes is quite complex and needs much more than one simple line of code. This is the gap that is filled with this command execution classes. There s a class for the command to be executed and a class for the execution of the command. Forking a subprocess and evaluating the result becomes so easy: try { // execute the command: /bin/ls -l /tmp mrw::exec ls = (mrw::cmd("/bin/ls"), "-l", "/tmp").execute(false); // evaluate the result if (ls.success()) std::cout<<"execution successful, result was:"<<std::endl; else std::cerr<<"error in execution, error was:"<<std::endl; std::cout<<ls.result()<<std::endl; std::cerr<<ls.error()<<std::endl; } catch (ExecutionFailedExc& x) { // a fatal execution error occurred // you can trace x.what() and x.stacktrace() } It is also possible to pass an stdin input argument to the subprocess called: try { mrw::exec cat = mrw::cmd("/bin/cat").execute("this is passed to stdin"); // "cat" passes all from stdin to stdout, therefore: assert(cat.result()=="this is passed to stdin"); } catch (...) {} // ignore

32 8.12 File and System Utilities 31 Classes class mrw::executionfailedexc Exception: Execution of command failed. class mrw::exec Execute a command in a new process. class mrw::partialexec Execute a UNIX program in non blocking parts. class mrw::cmd A system command to be executed File and System Utilities Detailed Description By now, some utilies for file handling, i.e. a copy command. Some file and system specific utilities are missing in C++ and often there is even no good alternative in C libraries. Classes class mrw::file File handling utilities. class mrw::dir Directory access Function Tracing (using log4cxx) Collaboration diagram for Function Tracing (using log4cxx): Debug Ut i l i t i es Funct i on Traci ng ( usi ng l og4cxx) Aut omat i c Funct i on Tr ace t o st andar d out f or GNU g++ Aut omat i c Funct i on Tr ace f or GNU g Detailed Description Precondition: #include <mrw/functiontrace.hpp>

33 8.13 Function Tracing (using log4cxx) 32 Place the macro MRW_METHOD as first line of all methods you want to trace, and macro MRW_FUNCTION as first line of all functions to be traced. There are alternative macros MRW_METHOD2 and MRW_FUNCTION2, that allow you to also specify the logging hierarchy. The default for the hierarchy string is "mrw.fntrace". The logging level is always DEBUG and cannot be changed. Attention: Be careful when you copy paste the declarations from one method to the other! Don t forget to correctly change the method s name! I recommend to use a tool like OpenC++ ( to automatically place function trace statements into classes, so that the coder does not have to care about. I have already partly written such a module and I will provide it for free (GPL) when it is good enough. The trace of the following code: \#include <mrw/functiontrace.hpp> \#include <log4cxx/basicconfigurator.h> void fn(int i=0) { MRW_FUNCTION("fn(int)"); // trace entry and exit if (i<4) fn(++i); } class A { public: A() { // not traced method(); } void method() { MRW_METHOD("A::method()"); // trace entry and exit fn(); } }; int main(int, char**) { log4cxx::basicconfigurator::configure(); MRW_FUNCTION("main(int, char**)"); A().method(); return 0; } Produces this output: 1 [ ] DEBUG mrw.fntrace - \ main(int, char**) 1 [ ] DEBUG mrw.fntrace - 0xbfffef3f: \ A::method() 1 [ ] DEBUG mrw.fntrace - \ fn(int) 2 [ ] DEBUG mrw.fntrace - \ fn(int) 2 [ ] DEBUG mrw.fntrace - \ fn(int) 2 [ ] DEBUG mrw.fntrace - \ fn(int) 2 [ ] DEBUG mrw.fntrace - \ fn(int) 2 [ ] DEBUG mrw.fntrace - / fn(int) 2 [ ] DEBUG mrw.fntrace - / fn(int) 2 [ ] DEBUG mrw.fntrace - / fn(int) 3 [ ] DEBUG mrw.fntrace - / fn(int) 3 [ ] DEBUG mrw.fntrace - / fn(int) 3 [ ] DEBUG mrw.fntrace - 0xbfffef3f: / A::method() 3 [ ] DEBUG mrw.fntrace - 0xbfffef3f: \ A::method()

34 8.13 Function Tracing (using log4cxx) 33 3 [ ] DEBUG mrw.fntrace - \ fn(int) 3 [ ] DEBUG mrw.fntrace - \ fn(int) 3 [ ] DEBUG mrw.fntrace - \ fn(int) 4 [ ] DEBUG mrw.fntrace - \ fn(int) 4 [ ] DEBUG mrw.fntrace - \ fn(int) 4 [ ] DEBUG mrw.fntrace - / fn(int) 4 [ ] DEBUG mrw.fntrace - / fn(int) 4 [ ] DEBUG mrw.fntrace - / fn(int) 4 [ ] DEBUG mrw.fntrace - / fn(int) 4 [ ] DEBUG mrw.fntrace - / fn(int) 4 [ ] DEBUG mrw.fntrace - 0xbfffef3f: / A::method() 5 [ ] DEBUG mrw.fntrace - / main(int, char**) The indentation is according to the call stack depth level, the name is preceded by a \ on entry and by a / on exit. The methods are preceded by the address of this, so that different instances can be distinguished. All before and including the dash - is configurable through the normal log4cxx trace patterns. Note: There is also a fully automagic function trace, similar to Automated Unexpected and Terminate Handler. It is described in Automatic Function Trace for GNU g++ and requires the GNU Compiler Collection gcc, because it makes use of a proprietary compiler feature. Modules Automatic Function Trace for GNU g++ Automatic Function Trace to standard out for GNU g++ Classes class mrw::fntrace Defines #define MRW_METHOD(name) mrw::fntrace fntrace(this, name, FILE, LINE ) Declare method entrance, place as first line in method. #define MRW_FUNCTION(name) mrw::fntrace fntrace(name, FILE, _- _LINE ) Declare function entrance, place as first line in functions. #define MRW_METHOD2(name, tracer) mrw::fntrace fntrace(this, name, - FILE, LINE, tracer) Declare method entrance, place as first line in method.

35 8.13 Function Tracing (using log4cxx) 34 #define MRW_FUNCTION2(name, tracer) mrw::fntrace fntrace(name, - FILE, LINE, tracer) Declare function entrance, place as first line in functions. Functions void cyg_profile_func_enter (void, void ) attribute ((no_instrument_- function)) Define Documentation #define MRW_FUNCTION(name) mrw::fntrace fntrace(name, - FILE, LINE ) Declare function entrance, place as first line in functions. Place this macro as first statement in each function that should write a function trace. Example: Parameters: namespace xxx { namespace yyy { void doit(int, char) { MRW_FUNCTION("xxx::yyy::doIt(int, char)"); [...] } } } name the full name of the function, including namespaces Definition at line 190 of file functiontrace.hpp #define MRW_FUNCTION2(name, tracer) mrw::fntrace fn- Trace(name, FILE, LINE, tracer) Declare function entrance, place as first line in functions. Place this macro as first statement in each function that should write a function trace. This macro allows you to define a logging hierarchy string. Example: namespace xxx { namespace yyy { void doit(int, char) { MRW_FUNCTION2("xxx::yyy::doIt(int, char)", "fn.xxx.yyy"); [...] } } }

36 8.13 Function Tracing (using log4cxx) 35 Parameters: name the full name of the function, including namespaces tracer the tracer hierarchy Definition at line 244 of file functiontrace.hpp #define MRW_METHOD(name) mrw::fntrace fntrace(this, name, _- _FILE, LINE ) Declare method entrance, place as first line in method. Place this macro as first statement in each method that should write a function trace. Example: Parameters: namespace xxx { namespace yyy { class Zzz { public: void doit(int, char) { MRW_METHOD("xxx::yyy::Zzz::doIt(int, char)"); [...] } }; } } name the full name of the method, including namespaces and class name Definition at line 168 of file functiontrace.hpp #define MRW_METHOD2(name, tracer) mrw::fntrace fntrace(this, name, FILE, LINE, tracer) Declare method entrance, place as first line in method. Place this macro as first statement in each method that should write a function trace. This macro allows you to define a logging hierarchy string. Example: Parameters: namespace xxx { namespace yyy { class Zzz { public: void doit(int, char) { MRW_METHOD2("xxx::yyy::Zzz::doIt(int, char)", "fn.xxx.yyy.zzz"); [...] } }; } } name the full name of the method, including namespaces and class name

C++ Exception Handling 1

C++ Exception Handling 1 C++ Exception Handling 1 An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such

More information

C++ TEMPLATES. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.

C++ TEMPLATES. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. C++ TEMPLATES http://www.tutorialspoint.com/cplusplus/cpp_templates.htm Copyright tutorialspoint.com Templates are the foundation of generic programming, which involves writing code in a way that is independent

More information

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011 More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors

More information

1 Introduction to C++ C++ basics, simple IO, and error handling

1 Introduction to C++ C++ basics, simple IO, and error handling 1 Introduction to C++ C++ basics, simple IO, and error handling 1 Preview on the origins of C++ "Hello, World!" programs namespaces to avoid collisions basic textual IO: reading and printing values exception

More information

C++ Crash Kurs. Exceptions. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck

C++ Crash Kurs. Exceptions. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck C++ Crash Kurs Exceptions Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck http://www.itm.uni-luebeck.de/people/pfisterer C++ Exceptions: Introduction What are exceptions Exceptions are

More information

Exception Safe Coding

Exception Safe Coding Exception Safe Coding Dirk Hutter hutter@compeng.uni-frankfurt.de Prof. Dr. Volker Lindenstruth FIAS Frankfurt Institute for Advanced Studies Goethe-Universität Frankfurt am Main, Germany http://compeng.uni-frankfurt.de

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files ... and systems programming C basic syntax functions arrays structs

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs. CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files... and systems programming C basic syntax functions arrays structs

More information

CS11 Advanced C++ Fall Lecture 3

CS11 Advanced C++ Fall Lecture 3 CS11 Advanced C++ Fall 2006-2007 Lecture 3 Today s Topics C++ Standard Exceptions Exception Cleanup Fun with Exceptions Exception Specifications C++ Exceptions Exceptions are nice for reporting many errors

More information

Object Oriented Programming Exception Handling

Object Oriented Programming Exception Handling Object Oriented Programming Exception Handling Budditha Hettige Department of Computer Science Programming Errors Types Syntax Errors Logical Errors Runtime Errors Syntax Errors Error in the syntax of

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Exception Handling Alternatives (Part 2)

Exception Handling Alternatives (Part 2) Exception Handling Alternatives (Part 2) First published in Overload 31 Copyright 1999 Detlef Vollmann Resume In part 1, several alternative mechanisms for handling exceptional events were presented. One

More information

This can be thrown by dynamic_cast. This is useful device to handle unexpected exceptions in a C++ program

This can be thrown by dynamic_cast. This is useful device to handle unexpected exceptions in a C++ program Abstract class Exception handling - Standard libraries - Generic Programming - templates class template - function template STL containers iterators function adaptors allocators -Parameterizing the class

More information

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***

More information

! Errors can be dealt with at place error occurs

! Errors can be dealt with at place error occurs UCLA Stat 1D Statistical Computing and Visualization in C++ Instructor: Ivo Dinov, Asst. Prof. in Statistics / Neurology University of California, Los Angeles, Winter 200 http://www.stat.ucla.edu/~dinov/courses_students.html

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

System Programming. Signals I

System Programming. Signals I Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 3 Signals

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 22 November 28, 2016 CPSC 427, Lecture 22 1/43 Exceptions (continued) Code Reuse Linear Containers Ordered Containers Multiple Inheritance

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 Introduction 2 IS 0020 Program Design and Software Tools Exception Handling Lecture 12 November 23, 200 Exceptions Indicates problem occurred in program Not common An "exception" to a program that usually

More information

CSC209 Review. Yeah! We made it!

CSC209 Review. Yeah! We made it! CSC209 Review Yeah! We made it! 1 CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files 2 ... and C programming... C basic syntax functions

More information

CS 326: Operating Systems. Process Execution. Lecture 5

CS 326: Operating Systems. Process Execution. Lecture 5 CS 326: Operating Systems Process Execution Lecture 5 Today s Schedule Process Creation Threads Limited Direct Execution Basic Scheduling 2/5/18 CS 326: Operating Systems 2 Today s Schedule Process Creation

More information

Lecture 2, September 4

Lecture 2, September 4 Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due

More information

Starting to Program in C++ (Basics & I/O)

Starting to Program in C++ (Basics & I/O) Copyright by Bruce A. Draper. 2017, All Rights Reserved. Starting to Program in C++ (Basics & I/O) On Tuesday of this week, we started learning C++ by example. We gave you both the Complex class code and

More information

Lecture 07 Debugging Programs with GDB

Lecture 07 Debugging Programs with GDB Lecture 07 Debugging Programs with GDB In this lecture What is debugging Most Common Type of errors Process of debugging Examples Further readings Exercises What is Debugging Debugging is the process of

More information

Homework 4. Any questions?

Homework 4. Any questions? CSE333 SECTION 8 Homework 4 Any questions? STL Standard Template Library Has many pre-build container classes STL containers store by value, not by reference Should try to use this as much as possible

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: C and Unix Overview This course is about computer organization, but since most of our programming is

More information

More on Templates. Shahram Rahatlou. Corso di Programmazione++

More on Templates. Shahram Rahatlou. Corso di Programmazione++ More on Templates Standard Template Library Shahram Rahatlou http://www.roma1.infn.it/people/rahatlou/programmazione++/ it/ / h tl / i / Corso di Programmazione++ Roma, 19 May 2008 More on Template Inheritance

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

1 of 8 3/28/2010 8:03 AM C++ Special Topics Home Class Info Links Lectures Newsgroup Assignmen This is a short review of special topics in C++ especially helpful for various assignments. These notes are

More information

Bash command shell language interpreter

Bash command shell language interpreter Principles of Programming Languages Bash command shell language interpreter Advanced seminar topic Louis Sugy & Baptiste Thémine Presentation on December 8th, 2017 Table of contents I. General information

More information

Outline. Zoltán Porkoláb: C++11/14 1

Outline. Zoltán Porkoláb: C++11/14 1 Outline Handling exceptional cases: errno, assert, longjmp Goals of exception handling Handlers and exceptions Standard exceptions Exception safe programming C++11 noexcept Exception_ptr, nested_exceptions

More information

Criterion Documentation

Criterion Documentation Criterion Documentation Release 2.3.0 Franklin "Snaipe" Mathieu Dec 07, 2016 Contents 1 Introduction 3 1.1 Philosophy................................................ 3 1.2 Features..................................................

More information

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476 CSE 451: Operating Systems Winter 2015 Module 4 Processes Mark Zbikowski mzbik@cs.washington.edu Allen Center 476 2013 Gribble, Lazowska, Levy, Zahorjan Process management This module begins a series of

More information

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized) Process management CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska lazowska@cs.washington.edu Allen Center 570 This module begins a series of topics on processes, threads, and synchronization

More information

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors

More information

G52CPP C++ Programming Lecture 16

G52CPP C++ Programming Lecture 16 G52CPP C++ Programming Lecture 16 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Casting static cast dynamic cast const cast reinterpret cast Implicit type conversion 2 How

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010 CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p. Welcome to Teach Yourself p. viii Acknowledgments p. xv Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p. 6 Standard C++: A Programming Language and a Library p. 8

More information

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018 CSCE 311 - Operating Systems Interrupts, Exceptions, and Signals Qiang Zeng, Ph.D. Fall 2018 Previous Class Process state transition Ready, blocked, running Call Stack Execution Context Process switch

More information

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534 CSE 410: Computer Systems Spring 2018 Processes John Zahorjan zahorjan@cs.washington.edu Allen Center 534 1. What is a process? Processes 2. What's the process namespace? 3. How are processes represented

More information

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

Interview Questions of C++

Interview Questions of C++ Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.

More information

When we program, we have to deal with errors. Our most basic aim is correctness, but we must

When we program, we have to deal with errors. Our most basic aim is correctness, but we must Chapter 5 Errors When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications, incomplete programs, and our own errors. When

More information

The following is an excerpt from Scott Meyers new book, Effective C++, Third Edition: 55 Specific Ways to Improve Your Programs and Designs.

The following is an excerpt from Scott Meyers new book, Effective C++, Third Edition: 55 Specific Ways to Improve Your Programs and Designs. The following is an excerpt from Scott Meyers new book, Effective C++, Third Edition: 55 Specific Ways to Improve Your Programs and Designs. Item 47: Use traits classes for information about types. The

More information

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

More information

III. Classes (Chap. 3)

III. Classes (Chap. 3) III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,

More information

Traditional Error Handling

Traditional Error Handling Exception Handling 1 Traditional Error Handling We have already covered several mechanisms for handling errors in C++. We ll quickly review them here. Returning Error Values One classic approach involves

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

A brief introduction to C++

A brief introduction to C++ A brief introduction to C++ Rupert Nash r.nash@epcc.ed.ac.uk 13 June 2018 1 References Bjarne Stroustrup, Programming: Principles and Practice Using C++ (2nd Ed.). Assumes very little but it s long Bjarne

More information

Lesson 3. The func procedure allows a user to choose the action upon receipt of a signal.

Lesson 3. The func procedure allows a user to choose the action upon receipt of a signal. Lesson 3 Signals: When a process terminates abnormally, it usually tries to send a signal indicating what went wrong. C programs can trap these for diagnostics. Software interrupts: Stop executing the

More information

377 Student Guide to C++

377 Student Guide to C++ 377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided

More information

System Calls & Signals. CS449 Spring 2016

System Calls & Signals. CS449 Spring 2016 System Calls & Signals CS449 Spring 2016 Operating system OS a layer of software interposed between the application program and the hardware Application programs Operating system Processor Main memory

More information

Exception Handling Pearson Education, Inc. All rights reserved.

Exception Handling Pearson Education, Inc. All rights reserved. 1 16 Exception Handling 2 I never forget a face, but in your case I ll make an exception. Groucho Marx It is common sense to take a method and try it. If it fails, admit it frankly and try another. But

More information

CS11 Introduction to C++ Fall Lecture 6

CS11 Introduction to C++ Fall Lecture 6 CS11 Introduction to C++ Fall 2006-2007 Lecture 6 Today s Topics C++ exceptions Introduction to templates How To Report Errors? C style of error reporting: return values For C Standard Library/UNIX functions,

More information

libknx Generated by Doxygen Wed Aug :37:55

libknx Generated by Doxygen Wed Aug :37:55 libknx Generated by Doxygen 1.8.1.2 Wed Aug 7 2013 01:37:55 Contents 1 KNX interface library 1 2 Namespace Index 3 2.1 Namespace List............................................ 3 3 Class Index 5 3.1

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial A Walkthrough with Examples CMSC 212 - Spring 2009 Last modified March 22, 2009 What is gdb? GNU Debugger A debugger for several languages, including C and C++ It allows you to inspect what the program

More information

Throwing exceptions 02/12/2018. Throwing objects. Exceptions

Throwing exceptions 02/12/2018. Throwing objects. Exceptions ECE 150 Fundamentals of Programming Outline 2 In this lesson, we will: See that we can throw objects Know that there are classes defined in the standard template library These classes allow more information

More information

Creating a Shell or Command Interperter Program CSCI411 Lab

Creating a Shell or Command Interperter Program CSCI411 Lab Creating a Shell or Command Interperter Program CSCI411 Lab Adapted from Linux Kernel Projects by Gary Nutt and Operating Systems by Tannenbaum Exercise Goal: You will learn how to write a LINUX shell

More information

Programs in memory. The layout of memory is roughly:

Programs in memory. The layout of memory is roughly: Memory 1 Programs in memory 2 The layout of memory is roughly: Virtual memory means that memory is allocated in pages or segments, accessed as if adjacent - the platform looks after this, so your program

More information

KU Compilerbau - Programming Assignment

KU Compilerbau - Programming Assignment 716.077 KU Compilerbau - Programming Assignment Univ.-Prof. Dr. Franz Wotawa, Birgit Hofer Institute for Software Technology, Graz University of Technology April 20, 2011 Introduction During this semester

More information

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1 Review of Fundamentals Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 GPL the shell SSH (secure shell) the Course Linux Server RTFM vi general shell review 2 These notes are available on

More information

de facto standard C library Contains a bunch of header files and APIs to do various tasks

de facto standard C library Contains a bunch of header files and APIs to do various tasks CSE333 SECTION 6 GNU C Library de facto standard C library Contains a bunch of header files and APIs to do various tasks Don t need to memorize everything Do need to know what if there s an API that can

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

More information

ch = argv[i][++j]; /* why does ++j but j++ does not? */

ch = argv[i][++j]; /* why does ++j but j++ does not? */ CMPS 12M Introduction to Data Structures Lab Lab Assignment 4 The purpose of this lab assignment is to get more practice programming in C, including the character functions in the library ctype.h, and

More information

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

More information

Generic Programming in C++: A modest example

Generic Programming in C++: A modest example Generic Programming in C++: A modest example Marshall Clow Qualcomm Technologies, Inc. mclow@qti.qualcomm.com marshall@idio.com http://cplusplusmusings.wordpress.com Twitter: @mclow Problem Definition

More information

Lecture 4 Threads. (chapter 4)

Lecture 4 Threads. (chapter 4) Bilkent University Department of Computer Engineering CS342 Operating Systems Lecture 4 Threads (chapter 4) Dr. İbrahim Körpeoğlu http://www.cs.bilkent.edu.tr/~korpe 1 References The slides here are adapted/modified

More information

Topics. bool and string types input/output library functions comments memory allocation templates classes

Topics. bool and string types input/output library functions comments memory allocation templates classes C++ Primer C++ is a major extension of c. It is similar to Java. The lectures in this course use pseudo-code (not C++). The textbook contains C++. The labs involve C++ programming. This lecture covers

More information

C Legacy Code Topics. Objectives. In this appendix you ll:

C Legacy Code Topics. Objectives. In this appendix you ll: cppfp2_appf_legacycode.fm Page 1 Monday, March 25, 2013 3:44 PM F C Legacy Code Topics Objectives In this appendix you ll: Redirect keyboard input to come from a file and redirect screen output to a file.

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

Recitation: Cache Lab & C

Recitation: Cache Lab & C 15-213 Recitation: Cache Lab & C Jack Biggs 16 Feb 2015 Agenda Buffer Lab! C Exercises! C Conventions! C Debugging! Version Control! Compilation! Buffer Lab... Is due soon. So maybe do it soon Agenda Buffer

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems Programs CSCI 4061 Introduction to Operating Systems C Program Structure Libraries and header files Compiling and building programs Executing and debugging Instructor: Abhishek Chandra Assume familiarity

More information

Introduction to Linked Lists. Introduction to Recursion Search Algorithms CS 311 Data Structures and Algorithms

Introduction to Linked Lists. Introduction to Recursion Search Algorithms CS 311 Data Structures and Algorithms Introduction to Linked Lists Introduction to Recursion Search Algorithms CS 311 Data Structures and Algorithms Lecture Slides Friday, September 25, 2009 Glenn G. Chappell Department of Computer Science

More information

CSE 333 Lecture smart pointers

CSE 333 Lecture smart pointers CSE 333 Lecture 14 -- smart pointers Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia New exercise out today, due Wednesday morning Exam Friday

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

6 Architecture of C++ programs

6 Architecture of C++ programs 6 Architecture of C++ programs 1 Preview managing memory and other resources "resource acquisition is initialization" (RAII) using std::auto_ptr and other smart pointers safe construction of an object

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1.... COMP6771 Advanced C++ Programming Week 5 Part One: Exception Handling 2016 www.cse.unsw.edu.au/ cs6771 2.... Memory Management & Exception Handling.1 Part I: Exception Handling Exception objects

More information

C++_ MARKS 40 MIN

C++_ MARKS 40 MIN C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float

More information

Topic 8: I/O. Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional)

Topic 8: I/O. Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional) Topic 8: I/O Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional) No C language primitives for I/O; all done via function

More information

Libgdb. Version 0.3 Oct Thomas Lord

Libgdb. Version 0.3 Oct Thomas Lord Libgdb Version 0.3 Oct 1993 Thomas Lord Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

More information

fedithead RichardJ.Mathar Generated by Doxygen Tue May :39:52

fedithead RichardJ.Mathar Generated by Doxygen Tue May :39:52 fedithead RichardJ.Mathar Generated by Doxygen 1.8.2 Tue May 14 2013 16:39:52 CONTENTS 1 Contents 1 Class Index 1 1.1 Class List............................................... 1 2 File Index 2 2.1 File

More information

CS354 gdb Tutorial Written by Chris Feilbach

CS354 gdb Tutorial Written by Chris Feilbach CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that

More information

Processes. Johan Montelius KTH

Processes. Johan Montelius KTH Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other

More information

CSE 303: Concepts and Tools for Software Development

CSE 303: Concepts and Tools for Software Development CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Error Handling and Exceptions Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de Summer

More information

Linux Operating System

Linux Operating System Linux Operating System Dept. of Computer Science & Engineering 1 History Linux is a modern, free operating system based on UNIX standards. First developed as a small but self-contained kernel in 1991 by

More information