"if b.0=1" funktioniert nicht

robert
Benutzer
Avatar
Gender: n/a
Location: Hildesheim / Deutschland
Posts: 249
Registered: 04 / 2006
Subject:

"if b.0=1" funktioniert nicht

 · 
Posted: 09.08.2010 - 11:39  ·  #1
Hallo,
warum geht das nicht? Die Zuweisung "b.0 := 1" funktioniert. Ich glaube, dass der Vergleich auch schon mal funktionierte....

Code
program bla;

Device = mega128, VCC=5;

Import
  SysTick,
  SerPort;

From System import ;


Define
  ProcClock      = 16000000;       {Hertz}
  SysTick        = 10;             {msec}
  StackSize      = $0100, iData;
  FrameSize      = $0100, iData;
  {----------------------------------------------------------------------------}
  SerPort        = 57600, Stop2;    {Baud, StopBits|Parity}
  RxBuffer       = 8, iData;
  TxBuffer       = 8, iData;

Implementation

{$IDATA}

const

type

var
  b : byte;

begin
  EnableInts;
  b.0 := 1;
  WriteLn(SerOut, ByteToBin(b));
  if (b.0 = 1) then
    WriteLn(SerOut, 'Hier sollte er hin...  ' + ByteToBin(b));
  else
    WriteLn(SerOut, 'aber hier geht er hin! ' + ByteToBin(b));
  endif;
end bla.
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: "if b.0=1" funktioniert nicht

 · 
Posted: 09.08.2010 - 11:59  ·  #2
Hi Robert.

My prefered way of dealing with this is

Code

var
  b: byte;
  b0 [@b,0] : bit;

...

  if b0 then...


Cheers

Merlin.
robert
Benutzer
Avatar
Gender: n/a
Location: Hildesheim / Deutschland
Posts: 249
Registered: 04 / 2006
Subject:

Re: "if b.0=1" funktioniert nicht

 · 
Posted: 09.08.2010 - 12:15  ·  #3
Hi Merlin,
yes, in most cases I make it like you. But sometimes, writing b.0 is easier. What do you do, if your var is located in the heap? In this case, you only know the adress at runtime.

If an expression like "if b.0 = 1" isn't allowed, the compiler should generate an error, but not wrong code!

robert
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: "if b.0=1" funktioniert nicht

 · 
Posted: 09.08.2010 - 12:23  ·  #4
Hi Robert.

Yes I agree that it should not generate wrong code.

To answer tour question about the heap (frame?) I have always used

if bit( b, 0) then
...

Regards

Merlin.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: "if b.0=1" funktioniert nicht

 · 
Posted: 09.08.2010 - 16:20  ·  #5
Hallo Robert,

der Ausdruck if b.x = gibt ein boolean (00/ff) zurück, ein compare mit "1" ergibt dehalb immer ein false.

rolf
robert
Benutzer
Avatar
Gender: n/a
Location: Hildesheim / Deutschland
Posts: 249
Registered: 04 / 2006
Subject:

Re: "if b.0=1" funktioniert nicht

 · 
Posted: 09.08.2010 - 16:39  ·  #6
Hallo Rolf,
dann ist es klar. Ist nur etwas verwirrend, weil man ja auch 0 und 1 zuweisen kann, nicht nur true und false.

Gruß
Robert

Habe gerade noch einmal was ausprobiert:
var bool : boolean;
if bool = 1 then... Compiler meldet ganz brav einen Type Mismatch
if true = 1 then... Compiler ignoriert die unterschiedlichen Typen.
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   109   123 · Page-Gen-Time: 0.143917s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI