Announcement

Collapse
No announcement yet.

C typedef to PB Type question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C typedef to PB Type question

    How do I handle the " DWORD fReserved : 25; " statement in PB?

    Code:
    'C++
    typedef struct _FTCOMSTAT { 
    	DWORD fCtsHold : 1; 
    	DWORD fDsrHold : 1; 
    	DWORD fRlsdHold : 1; 
    	DWORD fXoffHold : 1; 
    	DWORD fXoffSent : 1; 
    	DWORD fEof : 1; 
    	DWORD fTxim : 1; 
    	DWORD fReserved : 25; 
    	DWORD cbInQue; 
    	DWORD cbOutQue;
    } FTCOMSTAT, *LPFTCOMSTAT;
    
    
    ' PB  
    TYPE FTCOMSTAT
    	 fCtsHold AS DWORD ': 1;
    	 fDsrHold AS DWORD ': 1;
    	 fRlsdHold AS DWORD ': 1;
    	 fXoffHold AS DWORD ': 1;
    	 fXoffSent AS DWORD ': 1;
    	 fEof AS DWORD ': 1;
    	 fTxim AS DWORD ': 1;
    	 fReserved AS DWORD ': 25; ???
    	 cbInQue AS DWORD ';
    	 cbOutQue AS DWORD ';}
    END TYPE


    ------------------
    Wayne

    wayne_j_hill(at)yahoo.com
    '---------------
    Never argue with idiots. They'll drag you down to their level, then beat you with their experience.

  • #2
    I don't think this is possible Wayne.

    Forgive me if you know this, but a C/C++ statement like

    DWORD fCtsHold : 1;

    Says "Map or reserve 1 bit (from A DWORD) for this value"

    DWORD fReserved : 25;

    Says "Map or reserve aside 25 bits (from A DWORD) for this value"

    You'll notice that variables fCtsHold ... fReserved inclusive add up to 32 bits, the room in a DWORD ...

    So your TYPE declaration wouldn't work, i.e.

    fCtsHold AS DWORD

    Is 32 bits, not 1 etc. so your entire TYPE DEF is *far* wider than the C Struct your trying to mimic.

    I don't think PowerBASIC allows alottment down to the bit level, though I could be wrong. I think the best you could hope for is to make sure your TYPE DEF is the same width / data type and then pull out the individual bit values after dumping data to it by bit twiddling as required.

    Just sharing my ignorance really,

    Cheers,

    Michael.

    Comment


    • #3
      Like Michael says.

      See TYPE COMSTAT in your Win32API.inc file-- it's already defined.

      The ":#" thing is the C way of specifying bitfields. In PowerBASIC,
      you'll need to use something like the BIT function and statement,
      or AND/OR bitmasks, instead.

      ------------------
      Tom Hanlin
      PowerBASIC Staff

      Comment

      Working...
      X