none
VB.NET equivalence for char[4] c language data type, for storing IP address RRS feed

  • Question

  • Hi everyone:
    i read from the documentation of a dll that there is a struct that uses char[4] for storing an IP address. How can it be? and how come i can get to representate the same value in a string VB.NET data type, knowing that this is its equivalence (for char4)?
    Next is the data type definition

    '''unsigned char[4]

    <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=4)> _

    Public IP As String



    Thanks very much for your help!
     
    Tuesday, August 12, 2008 9:49 PM

Answers

  • The VB equivalent to C's  "unsigned char" is "Byte".  So, an unsigned char[4] would be an array of four bytes, passed by value in this case.


    -Ryan / Kardax
    • Marked as answer by Zhi-Xin Ye Monday, August 18, 2008 10:27 AM
    Tuesday, August 12, 2008 10:18 PM
  • An IP4 address is 4 bytes.  Since 'C' doesn't have a byte type and its "int" type size is implementation defined, 'C' programmers must jump through silly hoops like this to declare an IP address.  That's not an issue in the .NET framework, just declare it "As Integer".  That will always be exactly 4 bytes on any CPU architecture, at least for the next 20 years.  
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Monday, August 18, 2008 10:27 AM
    Friday, August 15, 2008 10:52 AM
    Moderator

All replies

  • The VB equivalent to C's  "unsigned char" is "Byte".  So, an unsigned char[4] would be an array of four bytes, passed by value in this case.


    -Ryan / Kardax
    • Marked as answer by Zhi-Xin Ye Monday, August 18, 2008 10:27 AM
    Tuesday, August 12, 2008 10:18 PM
  • An IP4 address is 4 bytes.  Since 'C' doesn't have a byte type and its "int" type size is implementation defined, 'C' programmers must jump through silly hoops like this to declare an IP address.  That's not an issue in the .NET framework, just declare it "As Integer".  That will always be exactly 4 bytes on any CPU architecture, at least for the next 20 years.  
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Monday, August 18, 2008 10:27 AM
    Friday, August 15, 2008 10:52 AM
    Moderator