Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi C++ pointer to byte array --> Delphi (https://www.delphipraxis.net/177855-c-pointer-byte-array-delphi.html)

Mikkey 2. Dez 2013 12:51

AW: Re: C++ pointer to byte array --> Delphi
 
Zitat:

Zitat von WojTec (Beitrag 1238172)
It mean if case 11 then process all, if 10 than all instead above, etc.?

And what about rest operations? Indexes are valid? 256 multiply is required?

Don't worry with 256: Multiplying with 256 is the same as shifting left 8 bits.

You must invent some construct for the C-Case, bcse the Delphi case has implicit C-"break"s. Perhaps like:

Delphi-Quellcode:
if length = 11 then ...
if length >= 10 then ...
if length >= 9 then ...
...

Namenloser 2. Dez 2013 12:53

AW: C++ pointer to byte array --> Delphi
 
Looks mostly good to me, but I would pay some extra attention to the type casts. I am not sure if
Delphi-Quellcode:
ord()
always gives the correct result here. In some places the type cast might be done to truncate a value. For example,
Delphi-Quellcode:
(ushort)foo
gives us the lowest 16 bits of
Delphi-Quellcode:
foo
.

And in the top code, I think you can get rid of
Delphi-Quellcode:
ord()
entirely, if you've correctly translated char as byte.

WojTec 2. Dez 2013 13:58

Re: C++ pointer to byte array --> Delphi
 
I completely don't understand what for is type casts from byte :o Variables whare are moved results can store entire data without truncating or something alse. What do you think?

Ord() is used, because AValue is string, I plan change it to TBytes.

Namenloser 2. Dez 2013 15:17

AW: Re: C++ pointer to byte array --> Delphi
 
Zitat:

Zitat von WojTec (Beitrag 1238189)
Variables whare are moved results can store entire data without truncating or something alse. What do you think?

I am not sure what you mean by that sentence, "whare" was not a word last time I checked ;).

I assume you wanted to say that the typecasts are unnecessary, which may be true. I didn't examine the code that closely, I was just saying that you should pay attention to that.

WojTec 2. Dez 2013 15:40

Re: AW: Re: C++ pointer to byte array --> Delphi
 
Zitat:

Zitat von Namenloser (Beitrag 1238200)
"whare" was not a word last time I checked ;).

Today I confused keys, because my brain is overloaded with obscure C syntax :(

Zitat:

Zitat von Namenloser (Beitrag 1238200)
I assume you wanted to say that the typecasts are unnecessary

Yes. But on the other hand code is written by professional, I'll try contact him.

Der schöne Günther 2. Dez 2013 16:59

AW: C++ pointer to byte array --> Delphi
 
You ignored me :(

I believe I explained why the upcast is necessary.

Namenloser 2. Dez 2013 17:04

AW: C++ pointer to byte array --> Delphi
 
Zitat:

Zitat von Der schöne Günther (Beitrag 1238237)
You ignored me :(

I believe I explained why the upcast is necessary.

I think in Delphi the upcast is done automatically by the compiler when the result is stored in a variable that is bigger than the operands.

Delphi-Quellcode:
var
  b: Byte;
  i: integer;
begin
  b := 255;
  i := b shl 2;
  // i should now hold the value 510
end

WojTec 2. Dez 2013 22:06

Re: AW: C++ pointer to byte array --> Delphi
 
Zitat:

Zitat von Der schöne Günther (Beitrag 1238237)
You ignored me :(

I believe I explained why the upcast is necessary.

Oh, no, I didn't ignored you ;)

You explained, but I still don't understand.

I checked it in this sample:

Delphi-Quellcode:
const
  C: Char = 'X';
var
  B: Byte absolute C;
begin
  ShowMessage(IntToStr(B shl 8)); // 22528
  ShowMessage(IntToStr((256*Byte(C)) shl 8)); // 5767168
  ShowMessage(IntToStr(Cardinal(Ord(C) shl 8))); // 22528
end;
Could you check in C++ what it returns? In Delphi I have 2901454111 for 'Delphi' string and 4357 seed.

Code:
#define mix(a,b,c) \
{ \
  a -= b; a -= c; a ^= ( c >> 13 ); \
  b -= c; b -= a; b ^= ( a << 8 ); \
  c -= a; c -= b; c ^= ( b >> 13 ); \
  a -= b; a -= c; a ^= ( c >> 12 ); \
  b -= c; b -= a; b ^= ( a << 16 ); \
  c -= a; c -= b; c ^= ( b >> 5 ); \
  a -= b; a -= c; a ^= ( c >> 3 ); \
  b -= c; b -= a; b ^= ( a << 10 ); \
  c -= a; c -= b; c ^= ( b >> 15 ); \
}


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:26 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz