Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-02

Function to set high and low Dword of a QWord

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luiz Americo Pereira Camara

Hi,

I'm looking to a function that will take two DWord as arguments and and returns a Qword where the low 4 bytes are the first DWord and the High 4 bytes the second DWord.

Something like MakeLong of win unit.

BTW

  TQWordRec = record
    D1: Dword;
    D2: DWord;
  end;

TQWordRec will have the same memory representation of the result of such function?

Thanks in advance.

Luiz

Reply by email

Jonas Maebe
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote
I'm looking to a function that will take two DWord as arguments and and returns a Qword where the low 4 bytes are the first DWord and the High 4 bytes the second DWord.
function makeqword(d1, d2: dword): qword;
begin
   result:=(qword(d2) shl 32) or d1;
end;
Show quoted text 7 lines
TQWordRec = record D1: Dword; D2: DWord; end; TQWordRec will have the same memory representation of the result of such function?

Only on little endian, on big endian it's the other way round.

Jonas

Reply by email

Luiz Americo Pereira Camara

Hi,

I'm looking to a function that will take two DWord as arguments and and returns a Qword where the low 4 bytes are the first DWord and the High 4 bytes the second DWord.

Something like MakeLong of win unit.

BTW

  TQWordRec = record
    D1: Dword;
    D2: DWord;
  end;

TQWordRec will have the same memory representation of the result of such function?

Thanks in advance.

Luiz

Reply by email

Luiz Americo Pereira Camara
to Jonas Maebe: function makeqword(d1, d2: dword): qword; begin result:=(qword(d2) shl 32) or d1; end;…
Jonas Maebe wrote 22 lines
On 28 feb 2007, at 17:51, Luiz Americo Pereira Camara wrote: > I'm looking to a function that will take two DWord as arguments and > and returns a Qword where the low 4 bytes are the first DWord and the > High 4 bytes the second DWord. function makeqword(d1, d2: dword): qword; begin result:=(qword(d2) shl 32) or d1; end; > TQWordRec = record > D1: Dword; > D2: DWord; > end; > > TQWordRec will have the same memory representation of the result of > such function? Only on little endian, on big endian it's the other way round.

Thanks

Luiz

Reply by email

Florian Klaempfl
to Jonas Maebe: function makeqword(d1, d2: dword): qword; begin result:=(qword(d2) shl 32) or d1; end;…
Show quoted text 11 lines
On 28 feb 2007, at 17:51, Luiz Americo Pereira Camara wrote: > I'm looking to a function that will take two DWord as arguments and > and returns a Qword where the low 4 bytes are the first DWord and the > High 4 bytes the second DWord. function makeqword(d1, d2: dword): qword; begin result:=(qword(d2) shl 32) or d1; end;

Cleaner imo:

lo(result):=d1;
hi(result):=d2;
Show quoted text 16 lines
> TQWordRec = record > D1: Dword; > D2: DWord; > end; > > TQWordRec will have the same memory representation of the result of > such function? Only on little endian, on big endian it's the other way round. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote 11 lines
Jonas Maebe schrieb: > > function makeqword(d1, d2: dword): qword; > begin > result:=(qword(d2) shl 32) or d1; > end; Cleaner imo: lo(result):=d1; hi(result):=d2;

I think this is a lot less clean (if only because lo/hi have different meanings in FPC and Delphi, making it less clear what the code does). Besides, lo()/hi() do not produce lvalues, so it doesn't even compile :)

Jonas

Reply by email

Florian Klaempfl
to Jonas Maebe
Show quoted text 17 lines
On 28 feb 2007, at 18:06, Florian Klaempfl wrote: > Jonas Maebe schrieb: >> >> function makeqword(d1, d2: dword): qword; >> begin >> result:=(qword(d2) shl 32) or d1; >> end; > > Cleaner imo: > > lo(result):=d1; > hi(result):=d2; I think this is a lot less clean (if only because lo/hi have different meanings in FPC and Delphi, making it less clear what the code does).

Well, it should generate better code ;)

Besides, lo()/hi() do not produce lvalues, so it doesn't even compile :)

Ops, I thought this worked :)

Reply by email