Path: news.mathworks.com!not-for-mail
From: "Akim " <aaa@bbb.ccc>
Newsgroups: comp.soft-sys.matlab
Subject: Re: C mex: working with integer mxArrays
Date: Wed, 6 Jan 2010 03:17:05 +0000 (UTC)
Organization: University of Melbourne
Lines: 29
Message-ID: <hi0vbh$68v$1@fred.mathworks.com>
References: <hi0oe8$g72$1@fred.mathworks.com> <b2ccedff-6d98-4192-a15c-89e0dbd887b8@m3g2000yqf.googlegroups.com>
Reply-To: "Akim " <aaa@bbb.ccc>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1262747825 6431 172.30.248.38 (6 Jan 2010 03:17:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 6 Jan 2010 03:17:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 757091
Xref: news.mathworks.com comp.soft-sys.matlab:596753

Rune Allnor <allnor@tele.ntnu.no> wrote in message <b2ccedff-6d98-4192-a15c-89e0dbd887b8@m3g2000yqf.googlegroups.com>...
> On 6 Jan, 02:19, "Akim " <a...@bbb.ccc> wrote:
> > Dear all,
> >
> > I'm new to mexs and C, and I'm trying to figure out the best way of working with Matlab data inside C mex functions. For double and logical Matlab data, the answer seems fairly straightforward if I understand correctly. For example:
> >
> > double *A;
> > mxLogical *B;
> >
> > A = mxGetPr(prhs[0]);   /*first input is a double*/
> > B = mxGetPr(prhs[1]);   /*second input is a logical*/
> >
> > *(A+1)=5;               /*assign 5 to second entry of A*/
> > *(B+1)=5;               /*assign 5 to second entry of B*/
> >
> > Now suppose that prhs[2] is of some integer type, e.g. uint32. What is the best way of declaring a pointer to prhs[2]? How do I know whether to use "int", "long int" or "short int"? If I'm not mistaken, sizes of ints vary from system to system.
> 
> Yes, they do. You will have to find out what C(++) data type
> matches the uint32 type. As far as I know, the C99 standard
> defines size-specific types. If you have a complying compiler
> you should cast to that type.
> 
> C++, on the other hand, have no such size-specific types, so
> you will have to look up the documentation of your system and
> compiler.
> 
> Rune

Thanks Rune -- it seems that I need "stdint.h", but my compiler doesn't support the C99 standard. For now I will opt for the simplest solution: I'll get my arrays as double, and then manually cast each array element to int.