Title | MPS does not compile from C++ |
Status | open |
Priority | nice |
Assigned user | Gareth Rees |
Organization | Ravenbrook |
Description | Christian 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?" |
Analysis | See 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 found | customer |
Evidence | [1] <https://info.ravenbrook.com/mail/2014/04/21/14-03-53/0/ >[2] < http://www.ravenbrook.com/project/mps/master/manual/html/guide/build.html >[3] < http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B > |
Created by | Gareth Rees |
Created on | 2014-04-21 16:01:53 |
Last modified by | Gareth Rees |
Last modified on | 2014-05-02 11:37:16 |
History | 2014-04-21 GDR Created. |