C++ const and mathlink
- To: mathgroup at smc.vnet.net
- Subject: [mg85667] C++ const and mathlink
- From: Art <grenander at gmail.com>
- Date: Tue, 19 Feb 2008 01:49:19 -0500 (EST)
I am writing mathlink wrappers for a C++ library on 6.0.1, Linux x86-64. I have a single .tm with no C++ code and a .cpp file. I am confused about the usage of const in several places: 1. Functions such as MLPutReal64List and MLEvaluate don't have const arguments. Is there any way to change their declaration through a define such as MLCONST in mathlink.h so that they are more const friendly. It seems like most of mathlink functions have const's in the declarations. I am wondering why these don't. Do they change their arguments? Is it safe to const_cast<>? The practical cost is that I have to instantiate array copies before returning them. 2. Can mprep generate declarations that have const's when using C++? If I define functions with const variables in my .cpp file, then I get link errors as the mprep generated declarations don't match. I've tried variations of mprep -prototypes (default on my system) and noprototypes, declaring my functions in the .tm file with consts like in the reverse.tm example, with no luck. Also, mprep leads to linker errors unless I set CC=g++. What is the correct way? The documentation and examples are very C friendly but not so much for C++. - Art