Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: C++ const and mathlink

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85711] Re: C++ const and mathlink
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 19 Feb 2008 07:09:56 -0500 (EST)
  • Organization: Uni Leipzig
  • References: <fpdudl$qs5$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,

as you pointed out:
"The documentation and examples are very C
 > friendly but not so much for C++."

because MathLink is for C, it work with C++, but
it is C and compatible with C compilers. So you will
not be able to tell a C library, that it should
understand the C++ const keyword because that are
different languages.

And "The practical cost is that" you have to remove the
const keyword from your arrays in you code.

Regards
   Jens

Art wrote:
> 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
> 


  • Prev by Date: Re: NDSolve[] and Differential Equations: Problem solving two similar
  • Next by Date: Re: Multiple data sets with ListPlot and different PointSizes - Mesh
  • Previous by thread: C++ const and mathlink
  • Next by thread: A Use for Interpretation