Results 1 to 2 of 2

Thread: Convert C Macro & Union to VB

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Michigan
    Posts
    304

    Convert C Macro & Union to VB

    I have the below C code I want to convert to VB. How do I convert the macro and union over?

    c--------------
    #define bf_N 16
    #define S(x,i)(bf_S[i][x.w.byte##i])
    union aword {
    unsigned long word;
    unsigned char byte [4];
    struct {
    unsigned int byte3:8;
    unsigned int byte2:8;
    unsigned int byte1:8;
    unsigned int byte0:8;
    } w;
    };

    vb-------------
    Public Const bf_N As Integer = 16
    Public Const S(x,i)(bf_S[i][x.w.byte##i])As ???????

  2. #2
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Convert C Macro & Union to VB

    You could even leave the first #define as a VB #Const:
    #Const bf_N = 16

    For the second #define macro, there really is no equivalent - turn it into a separate function if possible...
    #define S(x,i)(bf_S[i][x.w.byte##i])

    The rest translates roughly to the following (I say 'roughly' since there is no equivalent in VB for bit fields):

    Code:
    Public Structure aword
    	Public word As UInteger
    	Public [byte](3) As Byte
    
    	Public Structure AnonymousStruct
    		Public byte3 As UInteger
    		Public byte2 As UInteger
    		Public byte1 As UInteger
    		Public byte0 As UInteger
    	End Structure
    	Public w As AnonymousStruct
    End Structure
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width