AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

C++ pointer to byte array --> Delphi

Ein Thema von WojTec · begonnen am 1. Dez 2013 · letzter Beitrag vom 2. Dez 2013
Antwort Antwort
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.659 Beiträge
 
Delphi 12 Athens
 
#1

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

  Alt 2. Dez 2013, 12:29
I am not that familiar with C/C++, sry.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Namenloser

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

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

  Alt 2. Dez 2013, 12: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 12:55 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#3

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

  Alt 2. Dez 2013, 13: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
 
#4

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

  Alt 2. Dez 2013, 15: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
482 Beiträge
 
Delphi XE6 Professional
 
#5

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

  Alt 2. Dez 2013, 15: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

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

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

  Alt 2. Dez 2013, 16: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
 
#7

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

  Alt 2. Dez 2013, 17: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
482 Beiträge
 
Delphi XE6 Professional
 
#8

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

  Alt 2. Dez 2013, 22: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

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

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 04:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz