octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mxIs* functions now return bool


From: John W. Eaton
Subject: Re: mxIs* functions now return bool
Date: Sun, 11 Sep 2016 10:36:00 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0

On 09/11/2016 01:29 AM, Rik wrote:
9/10/16
I've been working on improving the MEX interface in Octave.  One of the
things I noticed is that the predicate tests in Matlab are all returning a
bool, whereas in Octave they return an int.  A predicate test might be
something like mxIsScalar or mxIsComplex.  Does anyone see a problem with
changing the function prototypes to return bool?

extern OCTINTERP_API int mxIsComplex (const mxArray *ptr);
=>
extern OCTINTERP_API bool mxIsComplex (const mxArray *ptr);

I suspect this is a relatively recent change in Matlab (for some value of relatively recent). I'm pretty sure they used to return int.

One of the things I don't understand is that the C language didn't have a
bool type until C99, and even then it was necessary to #include <stdbool.h>
in order to access it.  However, I accidentally coded mxIsScalar to return
bool and it has compiled correctly.  The only thing I see at the top of
mexproto.h is

#if defined (__cplusplus)
#  include <cstdlib>
extern "C" {
#else
#  include <stdlib.h>
#endif

When I run 'mex -v ...' I can see that the compiler is gcc, not g++, so I
don't think the first branch is being taken.  Should I worry and add the
include for stdbool.h when compiling with a straight C compiler?

If add -save-temps to the compiler command that is used and then look at the generated .i file can you see where bool is defined?

If I compile the simple program "bool x;" with gcc, it errors on the undefined bool type. So I think there must be some place that bool is being defined.

But I don't think it would hurt to include stdbool.h along with stdlib.h. If that causes trouble, I'm sure we'll hear about it.

jwe




reply via email to

[Prev in Thread] Current Thread [Next in Thread]