I am trying to cast a variable using the "ushort" type but am receiving an error of "u_short undeclared: first use of this function". I looked online and saw that it resides in the types.h header but when I try to include this header I receive another error of this header doesn't exist. Is this the correct header which I am trying to include or is there a way to get this header installed so I can make this conversion. Thanks!
sin.sin_port = htons((u_short)port);
$myTCP.c:7:60: error: types.h: No such file or directory
$myTCP.c: In function ‘myTCPconnect’:
$myTCP.c:48: error: ‘u_short’ undeclared (first use in this function)
My check of sys/types.h online didn't reveal either a "ushort" or a "u_short". (Notice that it would be sys/types.h, not types.h, and that would only work if you actually have it, as it's not a standard header.) I suppose you can check your own types.h, if you have one, and see if there is a "ushort" or a "u_short" defined.
I was looking at the header online and I believe that it just assigns "unsigned short" to u_short. After replace the (u_short) with the (unsigned short) everything appears to be working fine. Thank you for your help though.
What else would you expect it to be?
Originally Posted by NuNn
If you want your code to be portable, you should make your own typedefs rather than relying on headers that may not be in all compilers.
1. #include <stdint.h>
2. sys/types.h - as name suggests is system specific (normally this might come with the kernel as it is on Linux, glibc uses particular version of kernel headers which provide sys/types.h), might be u_short on one system, ushort on other system, and perhaps unsigned_short on yet another one, only stdint.h provides uniform typedefs
3. in stdint you have uint16_t... analogically for other types