AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

C++ pointer to byte array --> Delphi

Ein Thema von WojTec · begonnen am 1. Dez 2013 · letzter Beitrag vom 2. Dez 2013
Antwort Antwort
Seite 2 von 2     12   
Mikkey

Registriert seit: 5. Aug 2013
265 Beiträge
 
#11

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

  Alt 2. Dez 2013, 13:51
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 ...
...
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#12

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

  Alt 2. Dez 2013, 13:53
Looks mostly good to me, but I would pay some extra attention to the type casts. I am not sure if ord() always gives the correct result here. In some places the type cast might be done to truncate a value. For example, (ushort)foo gives us the lowest 16 bits of foo .

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

Geändert von Namenloser ( 2. Dez 2013 um 13:55 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#13

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

  Alt 2. Dez 2013, 14:58
I completely don't understand what for is type casts from byte 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.
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#14

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

  Alt 2. Dez 2013, 16:17
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.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#15

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

  Alt 2. Dez 2013, 16:40
"whare" was not a word last time I checked .
Today I confused keys, because my brain is overloaded with obscure C syntax

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.
  Mit Zitat antworten Zitat
Der schöne Günther
Online

Registriert seit: 6. Mär 2013
6.156 Beiträge
 
Delphi 10 Seattle Enterprise
 
#16

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

  Alt 2. Dez 2013, 17:59
You ignored me

I believe I explained why the upcast is necessary.
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#17

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

  Alt 2. Dez 2013, 18:04
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
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#18

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

  Alt 2. Dez 2013, 23:06
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 ); \
}
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:27 Uhr.
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