Thread Subject: I have the followi

Subject: I have the followi

From: Petros Mpogiatzis

Date: 23 Nov, 2009 12:38:04

Message: 1 of 3

Is there some problem with "&" operator and mex compiler? It try to compile for example the following (test.c):


----------------------------------------------------------------------------------------------------
#include "mex.h"

void add_them(double &k,double x, double y)
{
k=x+y;
}

void mexFunction(
    int nlhs, mxArray *plhs[],
    int nrhs, const mxArray *prhs[])
{
  double x,y,k;
     
  // get the inputs
  x=mxGetScalar(prhs[0]);
  y=mxGetScalar(prhs[1]);
    
  
  // call the function
  add_them(k,x,y);

  //create the output
  plhs[0]=mxCreateDoubleScalar(k);
  
  return;
}
------------------------------------------------------------------------------------------------------

and I get:


>>mex test.c
Error test.c: 3 syntax error; found `&' expecting `)'
Error test.c: 3 skipping `&' `k' `,'
Error test.c: 3 missing name for parameter 1 to function `add_them'
Error test.c: 3 syntax error; found `double' expecting `{'
Error test.c: 3 missing identifier
Error test.c: 3 syntax error; found `double' expecting `;'
Error test.c: 3 syntax error; found `)' expecting `;'
Error test.c: 3 skipping `)' `{'
Error test.c: 5 undeclared identifier `k'
Warning test.c: 3 possible usage of y before definition
Warning test.c: 3 possible usage of x before definition
Error test.c: 20 too many arguments to `add_them'
Error test.c: 20 too many arguments to `add_them'
Warning test.c: 12 possible usage of k before definition
11 errors, 3 warnings
------------------------------------------------------------------------------------------------------------------------


Thank you for your time

Subject: I have the followi

From: Nicolas Cusseau

Date: 23 Nov, 2009 12:44:03

Message: 2 of 3

"Petros Mpogiatzis" <painter@geo.auth.gr> wrote in message <hedvnb$laf$1@fred.mathworks.com>...
> Is there some problem with "&" operator and mex compiler? It try to compile for example the following (test.c):
>
>
> ----------------------------------------------------------------------------------------------------
> #include "mex.h"
>
> void add_them(double &k,double x, double y)
> {
> k=x+y;
> }
>
> void mexFunction(
> int nlhs, mxArray *plhs[],
> int nrhs, const mxArray *prhs[])
> {
> double x,y,k;
>
> // get the inputs
> x=mxGetScalar(prhs[0]);
> y=mxGetScalar(prhs[1]);
>
>
> // call the function
> add_them(k,x,y);
>
> //create the output
> plhs[0]=mxCreateDoubleScalar(k);
>
> return;
> }
> ------------------------------------------------------------------------------------------------------
>
> and I get:
>
>
> >>mex test.c
> Error test.c: 3 syntax error; found `&' expecting `)'
> Error test.c: 3 skipping `&' `k' `,'
> Error test.c: 3 missing name for parameter 1 to function `add_them'
> Error test.c: 3 syntax error; found `double' expecting `{'
> Error test.c: 3 missing identifier
> Error test.c: 3 syntax error; found `double' expecting `;'
> Error test.c: 3 syntax error; found `)' expecting `;'
> Error test.c: 3 skipping `)' `{'
> Error test.c: 5 undeclared identifier `k'
> Warning test.c: 3 possible usage of y before definition
> Warning test.c: 3 possible usage of x before definition
> Error test.c: 20 too many arguments to `add_them'
> Error test.c: 20 too many arguments to `add_them'
> Warning test.c: 12 possible usage of k before definition
> 11 errors, 3 warnings
> ------------------------------------------------------------------------------------------------------------------------
>
>
> Thank you for your time

Download a C++ compiler (Microsoft Visual C++ for a free trial)
Then type in the prompt:
   mex -setup
   mex add_them.cpp
 
You get your mex-file without error.

Regards,
nicolas

Subject: I have the followi

From: Petros Mpogiatzis

Date: 23 Nov, 2009 12:58:03

Message: 3 of 3

yeap, that's a fix. Thank you nicolas

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
syntax error fo... Petros Mpogiatzis 23 Nov, 2009 07:39:10
c Petros Mpogiatzis 23 Nov, 2009 07:39:09
mex Petros Mpogiatzis 23 Nov, 2009 07:39:09
rssFeed for this Thread

Contact us at files@mathworks.com