Compile problem ov.cc of octave-3.1.51 on cygwin

Tatsuro MATSUOKA tmacchant at yahoo.co.jp
Mon Jul 28 02:59:23 CDT 2008


Hello Jaroslav Hajek

Thank you for your sending a patch file.
I will try it tomorrow and the results will be reported here.


BTW
For mingw, gcc version is 3.4.5 while version of gcc on cygwin is 3.4.4.
For mingw, ov.cc seems to not be problem for octave 3.1.51 buiding.
 

Regards 

Tatsuro



--- Jaroslav Hajek <highegg at gmail.com> wrote:

> On Sat, Jul 26, 2008 at 11:48 PM, Tatsuro MATSUOKA
> <tmacchant at yahoo.co.jp> wrote:
> > Hello Jaroslav
> >
> > Thank you for your reply.
> >
> >
> > --- Jaroslav Hajek <highegg at gmail.com> wrote:
> >
> >> This  does not occur with g++ 4.2.1. Apparently the compiler is unable
> >> to convert octave_int<int32_t> to default int. I'm not sure how
> >> octave_idx_type comes into play because the offending line ov.cc:1361
> >> requests a conversion from int32NDArray to Array<int>.
> >> Can you try to compile the following simple test in the liboctave directory?
> >> test.cc:
> >> #include "config.h"
> >> #include "oct-inttypes.h"
> >> int main()
> >> {
> >>   int a;
> >>   octave_int32 b = 0;
> >>   a = b;
> >> }
> >>
> >> compile with `g++ -DHAVE_CONFIG_H -I. -I../ -I ../libcruft/misc/ -c test.cc'
> >>
> >> In any case, I'm sure it's desirable for any octave_int32<T> instance
> >> to be unambiguously convertible to default int and to octave_idx_type.
> >> So if you confirm this, then unless anyone objects, I'll make a patch
> >> to include the explicit conversions in octave_int32.
> >
> >
> > Tatsu at Inspiron6000 ~/octaves/octave-3.1.51/liboctave
> > $ g++ -DHAVE_CONFIG_H -I. -I../ -I ../libcruft/misc/ -c test.cc
> > test.cc: In function `int main()':
> > test.cc:7: error: conversion from `octave_int32' to `int' is ambiguous
> > oct-inttypes.h:324: note: candidates are: octave_int<T>::operator T() const [with T = int32_t]
> > oct-inttypes.h:328: note:  octave_int<T>::operator double() const [with T = int32_t]
> > oct-inttypes.h:330: note:  octave_int<T>::operator float() const [with T = int32_t]
> > test.cc:8:2: warning: no newline at end of file
> >
> > Perhaps your idea is right.  If you will make a patch for gcc-3.4.4 on cygwin, it will be
> helpful
> > for cygwin people.
> >
> > Regards
> >
> > Tatsuro
> >
> >
> >
> > --------------------------------------
> > Power up the Internet with Yahoo! Toolbar.
> > http://pr.mail.yahoo.co.jp/toolbar/
> >
> 
> After a little playing around, I've decided it will be best to fix the
> problem in place. See the attached patch. And anyway, this code seems
> even better than the previous one: it will likely avoid a double
> conversion.
> Still, I kind of feel that octave_int<> instances should be implicitly
> convertible to default int
> (or perhaps all integer types), but I see no easy way of doing it.
> 
> -- 
> RNDr. Jaroslav Hajek
> computing expert
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
> > # HG changeset patch
> # User Jaroslav Hajek <highegg at gmail.com>
> # Date 1217229472 -7200
> # Node ID 00a8a3a41a3a11c0f90038549cab3eed79dee7cc
> # Parent  dd5cc5016487f81a49b0f17a8127cdabc61a4c6c
> add explicit conversions from octave_int<T> to octave_idx_type and default int
> 
> diff --git a/src/ChangeLog b/src/ChangeLog
> --- a/src/ChangeLog
> +++ b/src/ChangeLog
> @@ -1,3 +1,8 @@
> +2008-07-28  Jaroslav Hajek <highegg at gmail.com>
> +
> +	* ov.cc (octave_value::int_vector_value): probe for every known integer type.
> +	* ov.cc (convert_to_int_array): New static function.
> +
>  2008-07-24  John W. Eaton  <jwe at octave.org>
>  
>  	* load-path.h (load_path::dir_info::class_info): New struct.
> diff --git a/src/ov.cc b/src/ov.cc
> --- a/src/ov.cc
> +++ b/src/ov.cc
> @@ -1346,6 +1346,17 @@
>                                               type_name (), "real vector"));
>  }
>  
> +template <class T>
> +static Array<int>
> +convert_to_int_array (const Array<octave_int<T> >& A)
> +{
> +  Array<int> O (A.dims ());
> +  octave_idx_type n = A.numel ();
> +  for (octave_idx_type i = 0; i < n; i++)
> +    O.xelem (i) = A.xelem (i).value ();
> +  return O;
> +}
> +
>  Array<int>
>  octave_value::int_vector_value (bool force_string_conv, bool require_int,
>  				bool force_vector_conversion) const
> @@ -1354,14 +1365,24 @@
>  
>    if (is_integer_type ())
>      {
> -      // query for the first type that is wide enough
> -#if SIZEOF_INT == 2
> -      retval = int16_array_value ();
> -#elif SIZEOF_INT == 4
> -      retval = int32_array_value ();
> -#else
> -      retval = int64_array_value ();
> -#endif
> +      if (is_int32_type ())
> +        retval = convert_to_int_array (int32_array_value ());
> +      else if (is_int64_type ())
> +        retval = convert_to_int_array (int64_array_value ());
> +      else if (is_int16_type ())
> +        retval = convert_to_int_array (int16_array_value ());
> +      else if (is_int8_type ())
> +        retval = convert_to_int_array (int8_array_value ());
> +      else if (is_uint32_type ())
> +        retval = convert_to_int_array (uint32_array_value ());
> +      else if (is_uint64_type ())
> +        retval = convert_to_int_array (uint64_array_value ());
> +      else if (is_uint16_type ())
> +        retval = convert_to_int_array (uint16_array_value ());
> +      else if (is_uint8_type ())
> +        retval = convert_to_int_array (uint8_array_value ());
> +      else
> +        retval = array_value (force_string_conv);
>      }
>    else 
>      {
> 


--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/


More information about the Bug-octave mailing list