Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

C++ const and mathlink

  • To: mathgroup at
  • Subject: [mg85667] C++ const and mathlink
  • From: Art <grenander at>
  • 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 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

  • Prev by Date: Re: an even faster way to normalize a
  • Next by Date: A Use for Interpretation
  • Previous by thread: Re: an even faster way to normalize a
  • Next by thread: Re: C++ const and mathlink