[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A question about the declaration of mxCreateStructArray in mex.
From: |
David Bateman |
Subject: |
Re: A question about the declaration of mxCreateStructArray in mex. |
Date: |
Fri, 20 Jul 2007 10:13:36 +0200 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Aquil H. Abdullah wrote:
> First let me say that I know that Octave is not Matlab so this post
> is mostly for clarity, (Although
>
> Matlab declares the function mxCreateStructArray as follows:
>
> mxArray *mxCreateStructArray(mwSize ndim, const mwSize *dims, int
> nfields,
> const char **fieldnames);
>
> Octave defines the function mxCreateStructArray as follows:
>
> mxArray *
> mxCreateStructArray (int ndims, int *dims, int num_keys, const char
> **keys)
> {
> return maybe_mark_array (new mxArray (ndims, dims, num_keys, keys));
> }
>
> While compiling a bit of mex code for use with octave I ran into the
> following error:
>
> Utils.cpp:38: error: invalid conversion from `const int*' to `int*'
> Utils.cpp:38: error: initializing argument 2 of `mxArray*
> mxCreateStructArray(int, int*, int, const char**)'
>
> To fix this I used a conditionally compiled the code that I was
> working on:
>
> #ifdef USE_OCTAVE
> mxArray * v = mxCreateStructArray(ndims, const_cast <int *>(dims),
> nFields, fields);
> #else
> mxArray * v = mxCreateStructArray(ndims, dims, nFields, fields);
> #endif
>
> Since a call to mxCreateStructArray eventually winds up in mxArray,
> which supplies a the constructor:
>
> mxArray (int ndims, const int *dims, int num_keys, const char **keys);
>
> I was wondering if there was a particular reason that
> mxCreateStructArray was implemented in its current fashion?
>
> Thanks!
Hi Aquil,
I think the reason *dims is not declared const here is purely an
oversight, and the const should just be added.. Patch attached against
the CVS.
David
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
*** ./src/mex.cc.orig50 2007-07-20 10:06:42.018433444 +0200
--- ./src/mex.cc 2007-07-20 10:07:40.425295509 +0200
***************
*** 2495,2501 ****
}
mxArray *
! mxCreateStructArray (mwSize ndims, mwSize *dims, int num_keys, const char
**keys)
{
return maybe_mark_array (new mxArray (ndims, dims, num_keys, keys));
}
--- 2495,2501 ----
}
mxArray *
! mxCreateStructArray (mwSize ndims, const mwSize *dims, int num_keys, const
char **keys)
{
return maybe_mark_array (new mxArray (ndims, dims, num_keys, keys));
}
*** ./src/mexproto.h.orig50 2007-07-20 10:06:35.977756987 +0200
--- ./src/mexproto.h 2007-07-20 10:06:56.055680837 +0200
***************
*** 123,129 ****
extern OCTINTERP_API mxArray *mxCreateSparse (mwSize m, mwSize n, mwSize
nzmax, mxComplexity flag);
extern OCTINTERP_API mxArray *mxCreateSparseLogicalMatrix (mwSize m, mwSize
n, mwSize nzmax);
extern OCTINTERP_API mxArray *mxCreateString (const char *str);
! extern OCTINTERP_API mxArray *mxCreateStructArray (mwSize ndims, mwSize
*dims, int num_keys, const char **keys);
extern OCTINTERP_API mxArray *mxCreateStructMatrix (mwSize rows, mwSize cols,
int num_keys, const char **keys);
// Copy constructor.
--- 123,129 ----
extern OCTINTERP_API mxArray *mxCreateSparse (mwSize m, mwSize n, mwSize
nzmax, mxComplexity flag);
extern OCTINTERP_API mxArray *mxCreateSparseLogicalMatrix (mwSize m, mwSize
n, mwSize nzmax);
extern OCTINTERP_API mxArray *mxCreateString (const char *str);
! extern OCTINTERP_API mxArray *mxCreateStructArray (mwSize ndims, const mwSize
*dims, int num_keys, const char **keys);
extern OCTINTERP_API mxArray *mxCreateStructMatrix (mwSize rows, mwSize cols,
int num_keys, const char **keys);
// Copy constructor.
2007-07-20 Aquil H. Abdullah <address@hidden>
* mex.cc (mxCreateStructArray): Declare second arg as const
* mexproto.h (mxCreateStructArray): Ditto.