| Coding conventions |
The following conventions are used throughout the C++ source code:
Use the following naming and case conventions:
When defining a data type my_type which is really a pointer to the representation class my_type_rep, use the standard mechanism for defining reference counted pointer classes. In the case of a simple class my_type, this is done using the following kind of code:
class string { INDIRECT_PROTO (string, string_rep) ... }; INDIRECT_IMPL (string, string_rep)
In the case of template classes, one should use similar macros INDIRECT_PROTO_1, etc.
To increase conciseness, we systematically abbreviate template definitions and template type names when defining new template classes. For instance, the code of the list<C> class is enclosed in a block of the form:
namespace mmx { #define TMPL_DEF template<typename C> #define TMPL template<typename C> #define List list<C> #define List_rep list_rep<C> ... #undef TMPL_DEF #undef TMPL #undef List #undef List_rep } // namespace mmx
There are probably more convention; please follow the style of existing code when writing new packages.
Static variables. The use of static variables in C++ can lead to weird effects within memory initialization and destruction. Their use is thus depreciated. For a local usage nesting a static variable inside a function that returns a read/write reference to the variable is often a good solution, for instance:
inline C& my_static_variable () { static C x = ...; return x; }
Otherwise, for variables that are global to a module, initialization and termination must be done by defining a my_package_instance class, whose constructor is the initialization routine and whose destructor is the termination routine (see for instance basix_instance in basix/src/basix.cpp.)
In case you run into a “segmentation fault” within the mmx-light shell, you can use gdb as follows, assuming that you are in development mode:
gdb mmxlight/build/.libs/mmx-light
[Enter the script]
[Crash information]
bt
In this way you will find the location of the crash inside the C++ source code. In order to obtain more information you must recompile the package involved with the –enable-debug option:
./configure ... --enable-debug