As most embedded programming is currently performed using C, it is likely that developers will need to transition their code and their working practice to C++. This session proposes a strategy that enables the benefits of C++ to be realized quickly and incrementally.
2. This is what a question slide will
look like.
Please answer in the chat.
Also, questions to me start with ?
2
[ # ]
3. 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
3
5. 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
5
6. 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);
...
}
6
7. 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
7
8. 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
8
9. Clean C
C:
Nested structures need care
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;
9
10. To view the rest of this course,
visit the full recorded version on Design News.
10