Page 1 of 1 1
Topic Options
#154686 - 2006-01-07 02:06 AM Possible NOT operator bug
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Okay, I'm not saying this is a bug quite yet.

Wanted to get other opinions first or explanation of why you think it works that way.


This code does not work!

Code:
If Not GetFileAttr('C:\BOGUS') & 16
MD 'C:\BOGUS'
'Recreated directory: ' + @ERROR + ' ' + @SERROR ?
EndIf



But this code does work!

Code:
If Not GetFileAttr(('C:\BOGUS') & 16)
MD 'C:\BOGUS'
'Recreated directory: ' + @ERROR + ' ' + @SERROR ?
EndIf



From the manual / or rather the .CHM of the manual has this example and it works.


Code:
 $Result = GetFileAttr(@LDRIVE + "\Kix32.exe")
IF GetFileAttr( "C:\TEMP" ) & 16
; Bitwise AND on 4th bit
? "C:\temp is a directory !"




Why does checking the folder there with the & 16 outside the parens work but using the NOT does not seem to work outside the parens.?
 
 

Top
#154687 - 2006-01-07 02:15 AM Re: Possible NOT operator bug
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
did some test round myself too:
Code:

GetFileAttr("C:\boogyman") ?
GetFileAttr("C:\boogyman") & 16 ?

VarTypeName(GetFileAttr("C:\boogyman") & 16) ?

Not GetFileAttr("C:\boogyman") & 16 ?
Not Not GetFileAttr("C:\boogyman") & 16 ?

Not (GetFileAttr("C:\boogyman") & 16) ?
Not Not (GetFileAttr("C:\boogyman") & 16) ?

Get $



the problem here is that operator precedence table does not show the position for binary operands.
and tbh, it's quite unclear otherwise too.

anyway, it seems that NOT has higher precedence than the binary stuff.
thus, NOT is executed before the & and the results make sense.
_________________________
!

download KiXnet

Top
#154688 - 2006-01-07 02:25 AM Re: Possible NOT operator bug
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
That sure is an odd way to force precedence. I would think that the *proper* way would be:
(GetFileAttr('C:\BOGUS') & 16)

Page 30 of the real manual explains precedence and while it does not make direct reference to &, it is in reality an AND operator which is listed. So, to sum it up, the expression() is first, NOT second, and AND last.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154689 - 2006-01-07 02:26 AM Re: Possible NOT operator bug
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Makes sense I suppose but think it should be documented some in the manual.

If you try

GetFileAttr(("C:\boogyman") & 16) ?

It will fail so the precedence is still not fully explained to me.
 

Top
#154690 - 2006-01-07 02:34 AM Re: Possible NOT operator bug
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, sorry.
the doc lists UNARY NOT and LOGICAL AND.
neither one is used in here.

we are using Logical NOT and Binary AND.
and the precedence is not the same as the one for the items in the list.
_________________________
!

download KiXnet

Top
#154691 - 2006-01-07 02:36 AM Re: Possible NOT operator bug
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
so?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154692 - 2006-01-07 02:39 AM Re: Possible NOT operator bug
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
what I am saying that LOGICAL operator is executed before BINARY operators

thus, the expression:
IF Not GetFileAttr( "C:\TEMP" ) & 16

is same as:
IF ((Not GetFileAttr( "C:\TEMP" )) & 16)

again, I can't proof this as we don't have a nice listing of the precedence here available.
but I remember some listing that showed BINARY NOT as the lowest of all in the precedence.
that would suggest that binary operands all are lower in the hierarchy than logical ones.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 4358 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.233 seconds in which 0.19 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org