The-Software-Experts |
|
![]() catch your bugs! |
Safe Coding in C Training
This course has the prerequisite that you already know the C programming language and have
some experience in programming. However there are some traps and pitfalls in C which you have to avoid
if you want to write C code of good quality. An analysis of the C standard will make you aware of the problematic
areas and will give you the understanding why these traps are in the programming language.
This is followed by a detailed exploration of each problematic area with examples and exercises. After the course
you will be able to understand and avoid the traps and pitfalls and restrict yourself to a safe subset of the
programming language. This subset will be similar to the suggested practices addressed by the MISRA standard. The course
has a length of 2 full days and can be held in English or German. The training material is in English.
I would be glad to receive your requests for
inhouse trainings. You can use our contact sheet for this.
The problem of C Standard
There is a C-standard, but not all things are defined by this standard.
Most programmers are not aware of these open and undefined items which often differ from compiler to compiler.
Only knowing about these problematic areas will make you a successful programmer. The following subjects will be addressed:
Difficulties in CExpressions
There are various possibilities of injecting errors into C expressions, as e.g. the mixing of data types.
Different data types are often used randomly and mixed in a
C-program without being aware of the implications. Additionally to this the compiler will perform promotion and
balancing which performs an implicit modification of the data types. Compiler mechanisms and the resulting pitfalls are
explained and shown in various examples. Further there is the influence of operators and other elements which
may lead to errors. E.g. there is a precedence of
operators in C, there are so called side effects and the order of their evaluation which may lead to
behaviour you would not have expected. The concepts and the resulting possible pitfalls are explained in detail. The
following areas are addressed:
Scope, Linkage and NamespacesThis part of the course will make you acquainted with the scope of data definitions and the linkage of data. From these principles possible errors may arise in your program, especially by later maintenance activities. It will be explained for which ranges of your program data can be defined and how the mechanisms of the compiler and linker work on the various data definitions. Further there are different namespaces in C, which means that the same identifier (name) can be used for various purposes. This could lead to confusion and should be avoided by naming restrictions. PointersPointers in C can be also a source of trouble. Some commonly performed sins will be pointer out in the course, their implicationts are explained and recommendations about how to avoid them are given. The Pre-ProcessorUsing the pre-processor the wrong way will make your program loose its portability. Some pre-processor mechanisms are eplained in the course which will improve your pre-processor usage. InterfacesThere are old style and new style interfaces in C. Some recommendations about their usage is given. Furhter there will be a lot of hints about how to avoid errors coming from a mismatch of interfaces between functions. MemoryC allows various types of memory usage. These types are explained and hints are given which ones are suitable for safe programming. Naming ConventionsHaving unclear namings of your variables in C may lead to unexpected trouble. A good naming convention which is followed strictly will help you to avoid many of the addressed problems as e.g. scope and linkage problems. Naming conventions are often seen as a formalistic effort without a lot of meaning. But quite the contrary is the case. They will make life easier in coding, maintenance and for inspections and they will help you to avoid errors in your program. Some important elements which should be present in names of variables and functions wil be outlined in the course. |
|