From help-octave-request at bevo dot che dot wisc dot edu Wed Jan 21 22:31:39 2004 Subject: Re: Testing endianness From: Paul Kienzle To: Octave_post Date: Wed, 21 Jan 2004 23:30:06 -0500 On Jan 21, 2004, at 4:38 PM, John W. Eaton wrote: > On 16-Jan-2004, Paul Kienzle wrote: > > | Do I need to test both conditions as in the following: > | > | if octave_config_info("words_little_endian") > | do little endian stuff > | elseif octave_config_info("words_big_endian") > | do big endian stuff > | else > | error("not little endian or big endian") > | endif > > Right, I wasn't sure what to do. We have both words_big_endian and > words_little_endian in C++, so I just put both in octave_config_info. > If neither are true, I imagine it is a bug. Would it be better to > have a different single value stored in octave_config_info? If so, > what would you like to call it? In suggesting a workaround for M. Cardoso, I chose only one of them: # untested code function r=is_big_endian static big=[]; if isempty(big) [fid,msg] = tmpfile(); if (fid < 0) error("%s",msg); end fwrite(fid, 1, 'long'); frewind(fid); big = fread(fid,1,'char')!=1 fclose(fid); endif r = big It is easy enough to query is_big_endian or !is_big_endian depending on need. Paul Kienzle pkienzle at users dot sf dot net ------------------------------------------------------------- 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 -------------------------------------------------------------