TRUE <> 0 ??

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
wasq
Posts: 5
Joined: 07 Jun 2018 17:19
Location: Россия, г. Самара

TRUE <> 0 ??

#1 Post by wasq » 04 Jan 2021 12:28

Hi !
Interesting BUT not working
true <> 0
false = 0;
The while statement does not work correctly in some cases.
Example

program test;
var aa:boolean;
begin
aa:=%10000000;
while NOT aa do;
end.

aa <> 0 means aa=true, ( NOT aa ) means = false. BUT

the while loop runs forever.
what to do??

Привет !
Интересно НО не работает
true <> 0
false = 0;
Оператор while работает не правильно в некоторых случаях.
Пример

program test;
var aa:boolean;
begin
aa:=%10000000;
while NOT aa do;
end.

aa <> 0 и aa=true, значит ( NOT aa ) = false. НО

цикл while работает вечно
Что делать ??

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: TRUE <> 0 ??

#2 Post by Dany » 12 Jan 2021 19:04

Using Pascal you should never think that a boolean can be acessed as an integer. The boolean values are "false" and "true" and the compiler respresents them internally as values unknown to you (and even if you accidentally know those values you shlould not use that knowledge in your programs, the compilermaker is free to change them without notice).
The only thing that is defined in the Pascal standard is: false < true.

program test;
var aa:boolean;
begin
aa:=%10000000; <-------------- you should not do this. In principle the compiler should give an error
while NOT aa do;
end.

p.s. Only in C "true" is defined as <>0
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

wasq
Posts: 5
Joined: 07 Jun 2018 17:19
Location: Россия, г. Самара

Re: TRUE <> 0 ??

#3 Post by wasq » 16 Jan 2021 15:43

Thanks Dany !
Also I found in the description MIKROPASCAL VER 7.01 == TRUE (all ones) or FALSE (zero)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: TRUE <> 0 ??

#4 Post by Dany » 25 Jan 2021 17:20

wasq wrote:
16 Jan 2021 15:43
Thanks Dany !
Also I found in the description MIKROPASCAL VER 7.01 == TRUE (all ones) or FALSE (zero)
Again, do not count on it (so, do not use that knowledge in your code)... this value is not defined in the Pascal language, it is defined by the compiler.
E.g. for the PIC24 "true" equals "1111111111111111" (as you see, again all ones, but 16 bits now).

In the C language "true" is defined as unequal to zero...
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for AVR General”