Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I convert c++ struct to pascal code?

Posted on 2007-03-30
5
Medium Priority
?
993 Views
Last Modified: 2008-01-09
Here is C++ struct code declaration:

      struct HLIST
      {
            char         Index;
            int            No:8 ,  Count:24;
            __int64    Offset;                              
      };


I don't know how can I convert bit declaration;;

Here is my code:

      THLIST = packed record
            Index: BYTE;
                No_Count: Integer;  //   int            No:8 ,  Count:24;
            Offset: Int64
      };

I try to declare whole 32bit data(No 8bit, Count 24bit = Total 32bit) to Integer type!!
Then get No and Count value by bit operation!!

 No = THList.No_Count and $000F;
 Count = THList.No_Count and $FFF0;


Is there any convert way gracefully to access each `No` and `Count` variables in record!!
0
Comment
Question by:byungho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 18824209
Actually the record has 2 integer components.  Try

      THLIST = packed record
            Index: BYTE;
                No   :    Integer;
                Count: Integer;  //   int            No:8 ,  Count:24;
            Offset: Int64
      };

mlmcc
0
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 250 total points
ID: 18824694
mlmcc is wrong (even with his credentials). Two integers do not work.
The struct is converted correctly. The only question is if it is really packed.
The only way to declare No and Count separately in Delphi is

      THLIST = packed record
            Index: Shortint;
            No: Shortint;
            Count: array [0..2] of Byte;
            Offset: Int64;
      end;

It does not really help you though. It is awkward to get the value of Count into a real Integer.
BTW Index is signed so Shortint is better. Alternatively use Char.
0
 

Author Comment

by:byungho
ID: 18825461
robert!! yes it packed!!  I want to access two variables separately!!

So is it impossible to convert pascal code? -_-;;; It is not easy to use!
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 18827670
The above gives you separate variables, but you will have to copy the 3 byte value to an Integer and also have to sign-extend it yourself. It therefore only helps you for "No". Write some access functions.
0
 

Author Comment

by:byungho
ID: 18827876
Thank you for reply~~ I'll try~
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question