From bug-octave-request at bevo dot che dot wisc dot edu Sat Dec 20 20:48:20 2003 Subject: Re: ftell - position of file pointer cannot be tested From: Schloegl Alois To: "John W. Eaton" Cc: bug-octave at bevo dot che dot wisc dot edu Date: Sat, 20 Dec 2003 07:40:46 -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. Let me get this right. You are saying, it is not possible anymore to implement something like this? fid = fopen(anyfile,'r'); s=fread(fid,10,'char'); % simple command, can be much more complicated, too. pos = ftell(fid); if pos == 10, 'postion is OK', else 'position is not correct', end; fclose(fid); % never forget to close a file. In other words, the position of the file pointer does not "Return the position of the file pointer as the number of characters from the beginning of the file FID" (quoted from help ftell). Alois ------------------------------------------------------------- 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 -------------------------------------------------------------