Re: request for change of boolean

new topic     » goto parent     » topic index » view thread      » older message » newer message

CChris wrote:
> 
> Kat wrote:
> > 
> > Derek Parnell wrote:
> > > 
> > > I disagree because by showing a specific example gave us some insight in
> > > to
> > > the way you are thinking, and that can't be a bad thing. However, in this
> > > specific
> > > example, it also showed us that you had a misunderstanding of the way that
> > > the
> > > open() function works. It does not return a boolean and thus your argument
> > > was
> > > weakened. It returns EITHER a valid file handle (a positive integer) OR an
> > > error
> > > flag (-1). 
> > 
> > I fully realise it returns a -1 when error, but i mistakenly hoped -1 could
> > be called FALSE, so when i used the filehandle as a boolean, the code would
> > run and read smoothly. The same happens when decrementing a flag or index,
> > and
> > testing it later: it becomes TRUE again when it goes negative. This just
> > smells
> > counter intuitive to me. For operations like open(), i consider non-positive
> > numerals as "there", but they are error codes, not indicators of success,
> > but
> > that's just in my lil book.
> > 
> > Perhaps i was misremembering pascal, i hope i get a little latitude since i
> > stopped writing new code years ago to deal with the dog situation here, when
> > my world was consumed with me not being consumed.
> > 
> > I do not remember how pascal typed bytebool, but i seem to remember it was
> > an
> > array of bits, which simply couldn't go negative, perhaps a bytebool was a
> > 0-255
> > byte. But likewise, i seem to be remembering if i typecast a string, mapped
> > an array of bytebool (or chars, didn't matter as there's no negative chars)
> > onto it, in an attempt to reduce memory needs, booleans still performed as
> > expected
> > when i stopped using that memory as "string" and began using it as "array of
> > bytebool". When they aren't 0-255 bytes, but instead are -127-+127 bytes, in
> > Euphoria, as Matt pointed out, they could be negative with lots of bits set
> > in that format, so a plain bit test fails to respond as i
> > expect(ed)(s)(ing).
> > Unless they were typecast as bytebool in pascal, which did different tests,,
> > i dunno.
> > 
> > 
> > Kat
> 
> I just installed the latest FreePascal IDE v2.2.0 from www.freepascal.org, and
> remembered your post. Here's what the docs say:
> <quote>
> 
> Boolean types
> 
> Free Pascal supports the Boolean type, with its two pre-defined possible
> values
> True and False.
> It also supports the ByteBool, WordBool and LongBool types. These are the only
> two values
> that can be assigned to a Boolean type. Of course, any expression that
> resolves
> to a boolean
> value, can also be assigned to a boolean type. Assuming B to be of type
> Boolean,
> the following
> 
> Table 3.3: Boolean types
> Name      Size Ord(True)
> Boolean    1    1
> ByteBool   1   Any nonzero value
> WordBool   2   Any nonzero value
> LongBool   4   Any nonzero value
> </quote>
> Note to self: Pasting from a .pdf isn't the best way to keep text formatting.
> 
> The previous version of FPC I was using had the same text. As I have hardly
> ever used bytebools myself, preferring cleaner (imho) booleans, I can't tell
> how it worked on other compilers.
>
> CChris

 From Turbo Pascal v6 Programmer Guide (oem hardcopy) book, 
page 24: ....Boolean is an enumerated type ....
page 218: .... An enumerated type is stored as an unsigned byte if the
enumeration has 256 or fewer values; otherwise, it is stored as an unsigned word.

In other words, it cannot be negative. Ergo, if a boolean compare result is
negative, it's an error or it's stored as zero, or FALSE. It makes sense to me
that if the code execution says putting a -1 into a boolean byte that can be only
positive, it's an error, it's FALSE, so a zero is put into the boolean because
ord(FALSE) = zero. This may be due to compiler error checking flags being set
just right, i don't remember. Or looked at another way, when a -1 is compared to
0 or 1 (it hasto be TRUE(1) or FALSE(0) to be legal), either result is FALSE, so
a 0 is stored in the boolean.

FreePascal v1.0.6 says the same, except for it having 32bit booleans too. And
64bit booleans? Hmm, googling FreePascal tells me it's the same, but now more
advanced than in 2002.

None of my TP5 or 6 or 7 help files will run on winxp, so i cannot check them. I
found only my TP6 books, which don't have bytebool, and little about booleans in
general, and almost nothing on the compiler or runtime switches, in the index or
contents. The 3rd party books don't address the alledged problem.

Anyhow, nevermind.

Kat

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu