From: Robert Klemme Date: 2006-10-13T23:05:29+09:00 Subject: Re: IO.readint ? On 12.10.2006 18:10, Kalman Noel wrote: > Tim Pease: >> On 10/12/06, Rolando Abarca wrote: >>> int b; >>> read(f, &b, sizeof(int)); >> class IO >> def geti( endian = :little ) >> str = self.read( 4 ) >> str = str.reverse if endian == :little >> str.unpack( 'N' )[0] >> end >> end > > Yet you cannot be sure that sizeof(int) is 4. > > Kalman class IO def geti( endian = :little ) str = read( [0].pack('N').length ) str.reverse! if endian == :little str.unpack( 'N' )[0] end end Regards robert