invalid type conversion when using C++ API

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

invalid type conversion when using C++ API

lqj1990
Hi all,

I'm new to Octave. I want to use some function in Octave using C++ API.
When I follow the tutorial
https://octave.org/doc/interpreter/Standalone-Programs.html (A.3), I
encounter an invalid type conversion problem.

The compiler shows that:
Severity Code Description Project File Line Suppression State
Error C2440 'static_cast': cannot convert from 'octave_idx_type *' to 'long
*' TestOctaveStandAlone
c:\octave\octave-4.4.0\include\octave-4.4.0\octave\dim-vector.h 156

The problem is located in oct-refcount.h, for the functions:
OCTAVE_ATOMIC_INCREMENT, OCTAVE_ATOMIC_DECREMENT,
OCTAVE_ATOMIC_POST_INCREMENT, OCTAVE_ATOMIC_POST_DECREMENT, in which a
variable x is converted from  octave_idx_type* to long*.

How can I resolve the problem?
I'm using VS2017, the compiler configuration is Debug, x64.
The Octave version is 4.4.0.

Thank you



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: invalid type conversion when using C++ API

Thomas D. Dean-2
On 05/27/18 15:45, lqj1990 wrote:

> Hi all,
>
> I'm new to Octave. I want to use some function in Octave using C++ API.
> When I follow the tutorial
> https://octave.org/doc/interpreter/Standalone-Programs.html (A.3), I
> encounter an invalid type conversion problem.
>
> The compiler shows that:
> Severity Code Description Project File Line Suppression State
> Error C2440 'static_cast': cannot convert from 'octave_idx_type *' to 'long
> *' TestOctaveStandAlone
> c:\octave\octave-4.4.0\include\octave-4.4.0\octave\dim-vector.h 156
>
> The problem is located in oct-refcount.h, for the functions:
> OCTAVE_ATOMIC_INCREMENT, OCTAVE_ATOMIC_DECREMENT,
> OCTAVE_ATOMIC_POST_INCREMENT, OCTAVE_ATOMIC_POST_DECREMENT, in which a
> variable x is converted from  octave_idx_type* to long*.
>
> How can I resolve the problem?
> I'm using VS2017, the compiler configuration is Debug, x64.
> The Octave version is 4.4.0.
>
> Thank you

This seems to work for me.  Octave 4.3.0+

 > mkoctfile --link-stand-alone standalone.cc -o standalone
 > ./standalone
Hello Octave world!
  11 12
  21 22

Tom Dean


Reply | Threaded
Open this post in threaded view
|

Re: invalid type conversion when using C++ API

Thomas D. Dean-2
In reply to this post by lqj1990
On 05/27/18 15:45, lqj1990 wrote:

> Hi all,
>
> I'm new to Octave. I want to use some function in Octave using C++ API.
> When I follow the tutorial
> https://octave.org/doc/interpreter/Standalone-Programs.html (A.3), I
> encounter an invalid type conversion problem.
>
> The compiler shows that:
> Severity Code Description Project File Line Suppression State
> Error C2440 'static_cast': cannot convert from 'octave_idx_type *' to 'long
> *' TestOctaveStandAlone
> c:\octave\octave-4.4.0\include\octave-4.4.0\octave\dim-vector.h 156
>
> The problem is located in oct-refcount.h, for the functions:
> OCTAVE_ATOMIC_INCREMENT, OCTAVE_ATOMIC_DECREMENT,
> OCTAVE_ATOMIC_POST_INCREMENT, OCTAVE_ATOMIC_POST_DECREMENT, in which a
> variable x is converted from  octave_idx_type* to long*.
>
> How can I resolve the problem?
> I'm using VS2017, the compiler configuration is Debug, x64.
> The Octave version is 4.4.0.

This seems to work for me.  Octave 4.3.0+

 > mkoctfile --link-stand-alone standalone.cc -o standalone
 > ./standalone
Hello Octave world!
  11 12
  21 22

Tom Dean


Reply | Threaded
Open this post in threaded view
|

Re: invalid type conversion when using C++ API

mmuetzel
> The compiler shows that:
> Severity Code Description Project File Line Suppression State
> Error C2440 'static_cast': cannot convert from 'octave_idx_type *' to
> 'long
> *' TestOctaveStandAlone
> c:\octave\octave-4.4.0\include\octave-4.4.0\octave\dim-vector.h 156
>
> The problem is located in oct-refcount.h, for the functions:
> OCTAVE_ATOMIC_INCREMENT, OCTAVE_ATOMIC_DECREMENT,
> OCTAVE_ATOMIC_POST_INCREMENT, OCTAVE_ATOMIC_POST_DECREMENT, in which a
> variable x is converted from  octave_idx_type* to long*.

That a static_cast from 'octave_idx_type *' to 'long *' works on some
systems and not on others is probably because "long" is of different size
dependent on host and architecture.

> How can I resolve the problem?

Maybe it would work using a reinterpret_cast instead...



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html