MPS issue job003770

TitleMPS does not compile from C++
Assigned userGareth Rees
DescriptionChristian Schafmeister reports [1]: "I have my obj_scan/obj_skip functions written in C++ and I’d like to compile MPS into my code as described in the MPS build guide 2.3.3 [2]. How would I do that?"
AnalysisSee Wikipedia [3] for an overview of the incompatibilities between the languages. We encounter the following difficulties:

1. We use the C++ keywords "class", "new", "delete" and "this" as variable and parameter names. [It would be straightforward to change these names.]

2. In C it is legal and well-defined to assign any pointer variable from a value of type void* or vice versa. We rely on this feature of C to convert between "client" pointers (void*) and internal pointers (Addr). These assignments are not legal in C++: there must be an explicit cast. [We could have macros to do these conversions. It might even be helpful to add them because it would make it clearer where these conversions are happening.]

3. In C++ a nested struct type is only defined within the scope of the outer struct. We'd have to pull out some of these to top-level declarations to make the names available.

4. We take some care to avoid violating the strict aliasing rule in C (by not referring to the same object via pointers of two different types, except via the two well-defined mechanisms — assignment to void* and cast to char*). But what's the equivalent rule and workarounds in C++?
How foundcustomer
Evidence[1] <>
[2] <>
[3] <>
Created byGareth Rees
Created on2014-04-21 16:01:53
Last modified byGareth Rees
Last modified on2014-05-02 11:37:16
History2014-04-21 GDR Created.