Path: news.mathworks.com!not-for-mail
From: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: C mex: working with integer mxArrays
Date: Wed, 6 Jan 2010 10:53:05 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 29
Message-ID: <hi1q2h$c4f$1@fred.mathworks.com>
References: <hi0oe8$g72$1@fred.mathworks.com> <hi1eku$irh$1@fred.mathworks.com> <hi1ltt$588$1@fred.mathworks.com>
Reply-To: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1262775185 12431 172.30.248.37 (6 Jan 2010 10:53:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 6 Jan 2010 10:53:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: news.mathworks.com comp.soft-sys.matlab:596819

Dear Akim!

> So if I understand correctly, an unsigned char pointer and an mxLogical pointer are essentially equivalent. Does it matter which one I use?

*Actually* the replied pointers are equal:
double *p1;
mxLogical *p2;
int16_T *p3;
void *p4;
char *p5;

  p1 = mxGetPr(prhs[0]);
  p2 = (mxLogical *) mxGetData(prhs[0]);
  p3 = (int16_T *) mxGetData(prhs[0]);
  p4 = mxGetData(prhs[0]);
  p5 = (char *) mxGetData(prhs[0]);

All pointers point to the same memory location!
*But*: 
1. if prhs[0] is a LOGICAL array, [p2] is the most descriptive pointer. Debugging programs is the most challenging work and every method to increase clarity should be used!
2. The following expressions do *not* (all) point to the same memory location:
  p1[1], p2[1], p3[1], p4[1], p5[1]
  p1 +1, p2 + 1, and so on.
The double pointer p1[1] points to the 2nd double of the array, which is the 9th byte.
The mxLogical pointer p2[1] points to the 2nd mxLogical, which is the 2nd byte.

Another tip: the names I've choosen are dull: "p1", "p2"... How much easier would it be, if I'd use "p_double", "p_logical"...

Perhaps this helps, if you are a C beginner. Good luck, Jan