Re: global constant variables in mex
- From: Peter Boettcher <boettcher@xxxxxxxxxx>
- Date: Mon, 25 Jun 2007 12:58:21 -0400
"Jon Erickson" <erickson@xxxxxxxxxxx> writes:
Thanks very much for the fast response!
All of it makes sense except the following.
You suggested trying
static int N;
I did this (both before my original post and retried after reading
Specifically I did
static int N;
N = (int)mxGetScalar(prhs);
I still get the same kind of error:
Error newsalpamex.cc: 228 integer expression must be constant
I understand why this is happening , but
The thing I'm surprised about is that the compiler doesn't recognize
that I never try to update the value for N after the first call to
mxGetScalar. So it is in fact a constant once the first call to
mxGetScalar is finished. Maybe I'm expecting too much out of c
It's not the fact that it is assigned to only once, but that fact that
the compiler doesn't know the size at compile time.
This restriction is not present in later C standards, C99, for
instance, and many compilers will probably handle it just fine,
treating it as some C/C99/C++ hybrid.
So my (probably very naive/stupid) question is:
can you please give a specific example how to pass a variable to a
mex function (from another matlab function, say) which is
subsequently declared as a global constant.
In ANSI C, global constants can only be assigned at declaration time,
and only with a value that the compiler can figure out at compile
time. So think of a different way :)
I'll probably just end up using your suggestion to do
but I'm curious to see how a pro would do it.
The #define N_MAX is how I would do it, unless my N_MAX were really
large, in which case I would use the mxMalloc suggestion.
- Prev by Date: Re: CORRCOEF and NAN
- Next by Date: Re: Speed up...How?!
- Previous by thread: Re: global constant variables in mex
- Next by thread: Derivative