AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Von C++ nach Delphi (Union + Struct)

Ein Thema von Alter Mann · begonnen am 18. Mai 2011 · letzter Beitrag vom 19. Mai 2011
Antwort Antwort
Robotiker
(Gast)

n/a Beiträge
 
#1

AW: Von C++ nach Delphi (Union + Struct)

  Alt 19. Mai 2011, 07:55
Hallo,

hier ist die Doku zu Bitfeldern beim C++ Builder und Visual C++
http://docwiki.embarcadero.com/RADStudio/en/Bit_Fields
http://msdn.microsoft.com/de-de/library/ewwyfdbe.aspx

Man sollte auch schauen, von welchem C++ Compiler der umzusetzende Code kommt, denn in der C++ Builder Doku steht:

Zitat:
According to the C and C++ language specifications, the alignment and storage of bit fields is implementation defined. Therefore, compilers can align and store bit fields differently. If you want complete control over the layout of bit fields, it is advisable to write your own bit field accessing routines and create your own bit fields.
  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#2

AW: Von C++ nach Delphi (Union + Struct)

  Alt 19. Mai 2011, 08:06
Hier mal mein Vorschlag für D7:

Delphi-Quellcode:
type
  TBMRecContent = (bmRecipient, bmReserved, bmType, bmDir);
  TBMRec = record
    data : Byte;
  end;

  _BM_REQUEST_TYPE = packed record
    case Byte of
      0 : (_BM: TBMRec);
      1 : (B: Byte);
  end;

:

implementation

:

function getBMRecContent(BMRecContent:TBMRecContent; BMRec:TBMRec): Byte;
begin
  case BMRecContent of
    bmRecipient: result := (BMRec.data shr 6) and 3;
    bmReserved: result := (BMRec.data shr 3) and 7;
    bmType: result := (BMRec.data shr 1) and 3;
    bmDir: result := (BMRec.data and 1);
  else
    Result:=0;
  end;
end;

procedure TForm.ButtonClick(Sender: TObject);
var BM_REQUEST_TYPE: _BM_REQUEST_TYPE;
begin
  BM_REQUEST_TYPE._BM.data:=3;
  ShowMessage(Format(
    'Recipient = %d, Reserved = %d, Type = %d, Dir = %d',
    [getBMRecContent(bmRecipient, BM_REQUEST_TYPE._BM),
     getBMRecContent(bmReserved, BM_REQUEST_TYPE._BM),
     getBMRecContent(bmType, BM_REQUEST_TYPE._BM),
     getBMRecContent(bmDir, BM_REQUEST_TYPE._BM)]
  ));
end;

Geändert von omata (19. Mai 2011 um 08:45 Uhr)
  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 21:25 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