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 работает вечно
Что делать ??
TRUE <> 0 ??
Re: TRUE <> 0 ??
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
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)
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)
Re: TRUE <> 0 ??
Thanks Dany !
Also I found in the description MIKROPASCAL VER 7.01 == TRUE (all ones) or FALSE (zero)
Also I found in the description MIKROPASCAL VER 7.01 == TRUE (all ones) or FALSE (zero)
Re: TRUE <> 0 ??
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)
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)