From bug-octave-request at bevo dot che dot wisc dot edu Sun Jan 4 15:14:45 2004 Subject: Re: ftell - position of file pointer cannot be tested From: Schloegl Alois To: bug-octave at bevo dot che dot wisc dot edu Date: Sun, 4 Jan 2004 14:19:06 -0600 Zitat von "John W. Eaton" : > On 19-Dec-2003, Schloegl Alois wrote: > > | Bug report for Octave 2.1.52 configured for i686-pc-linux-gnu > | > | Description: > | ----------- > | > | > | fid = fopen(anyfile); > | s = fread(fid,500,'char'); > | octave:4> ftell(fid)~=500 > | error: binary operator `==' not implemented for `streamoff' by `scalar' > | operations > | error: evaluating binary operator `==' near line 4, column 11 > | > | ftell returns a value of type 'streamoff' which cannot be compared against > a > | numeric value. In this way, ftell is pretty useless. > | > | Is there any reason, why ftell does not return a scalar value? > > Yes, because the object that is returned by the C++ stream classes to > represent file positions is no longer a long integer, and can't be > converted to one (it might not fit). There was a short discussion > about this problem a month or two ago, I think on the > octave-maintainers mailing list. > > | Repeat-By: > | --------- > | > | fid = fopen(anyfile); > | s = fread(fid,500,'char'); > | ftell(fid)==500, > | error: binary operator `==' not implemented for `streamoff' by `scalar' > | operations > | error: evaluating binary operator `==' near line 4, column 11 > | > | Fix: > | --- > | > | ftell should return a scalar value or > | the comparison operator must handle "streamoff" data. > > I think the comparision operator does handle streamoff data. But you > are comparing a streamoff object with a scalar (double precision > number). AFAICT, the underlying C++ objects have no way to convert > between the two, so I don't see a good way to fix this. > > jwe > The following patch solves the problem, at least for me. I'm using gcc 3.3.3 Alois *** cvs/octave2/src/file-io.cc Sun Jan 4 19:01:55 2004 --- cvs/octave/src/file-io.cc Sun Jan 4 19:42:34 2004 *************** *** 633,639 **** from the beginning of the file at var{fid} dot \n\ at end deftypefn") { ! octave_value retval = (long long) -1; int nargin = args.length (); --- 633,639 ---- from the beginning of the file at var{fid} dot \n\ at end deftypefn") { ! octave_value retval = streamoff_array (dim_vector (1, 1), -1); int nargin = args.length (); *************** *** 642,648 **** octave_stream os = octave_stream_list::lookup (args(0), "ftell"); if (! error_state) ! retval = (long long) os.tell (); } else print_usage ("ftell"); --- 642,648 ---- octave_stream os = octave_stream_list::lookup (args(0), "ftell"); if (! error_state) ! retval = streamoff_array (dim_vector (1, 1), os.tell ()); } else print_usage ("ftell"); ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------