100 likes | 261 Views
Programming Embedded Systems in C++ . A C to C++ Migration Strategy . 20 May 2014 Colin Walls, Mentor Graphics. [ # ]. This is what a question slide will look like. Please answer in the chat. Also, questions to me start with ?. Agenda. Monday : C++ for Embedded Programming
E N D
Programming Embedded Systems in C++ A C to C++ Migration Strategy 20 May 2014Colin Walls, Mentor Graphics
[ # ] This is what a question slide will look like.Please answer in the chat. Also, questions to me start with ?
Agenda Monday: C++ for Embedded Programming Tuesday: C to C++ Migration Strategy Wednesday: C++ and a Real Time Operating System Thursday: Case study #1 Friday: Case Study #2
[ 1 ] What language are you using for embedded development today?
C to C++ Migration • Three stage process: • exploit reusability • new code in C++ • link with C code • treat C as C++ • clean up C code to comply with C++ • start using C++ language features
Apply Reusability • All new code in C++ • link with existing C modules • Problem with typesafe linkage • C++ function names and references manged fun(int) becomes fun_int(int) • C functions not mangled fun(int) unchanged • use extern "C" extern "C" { void funx(int); int fun(float); ... }
Clean C • ANSI C is essentially a subset of C++ • Numerous minor exceptions • Clean C is true subset • code written or modified to accommodate exceptions • still ANSI C • specific points to address • Treat Clean C as if it were C++ • acceptable to C++ compiler • type-safe linkage OK
Clean C • Function prototypes are mandatory • Implicit types casts are a problem • use explicit – like (char) • Enumerated types are taken “seriously” • Character arrays must have room for terminator char str[3] = "xyz"; is not acceptable char str[] = "xyz"; is better
Clean C Nested structures need care C: struct out { struct in { int i; } m; int j; }; struct in inner; struct out outer; Clean C: struct in { int i; }; struct out { struct in m; int j; }; struct in inner; struct out outer;
To view the rest of this course, visit the full recorded version on Design News.