2

谁能告诉我要用于等的头u_short文件u_char

我已经看到它被用于sys/socket.h

typedef u_char      sa_family_t;

但是当我在我的程序中使用该标题时,它给了我错误:

1>c:\program files\microsoft visual studio 10.0\vc\include\sys\socket.h(52):
error C2146: syntax error : missing ';' before identifier 'sa_family_t'

我认为解决方案是包含标题,但我不知道它是什么标题!

4

1 回答 1

0

Header file for u_short?

We just ramped up testing on less-frequently-used platforms. We ran into a similar issue under Cygwin i686 with GCC 5.3 and -std=c++11. The code has been stable for about 15 years (give or take).

I can't find a standard header for it.

Grepping on OS X and Linux shows u_short is fairly prevalent, even though there are 0 hits under Cygwin now (JUN 2016):

# Ununtu
$ grep -IR "u_short" /usr/include | wc -l
 31

# OS X
$ grep -IR "u_short" /usr/include | wc -l
 122

# Solaris
$ /usr/gnu/bin/grep -IR "u_short" /usr/include/ | wc -l
 125

And:

# Ubuntu
$ grep -IR "u_short" /usr/include | grep typedef
/usr/include/x86_64-linux-gnu/bits/types.h:typedef unsigned short int __u_short;
/usr/include/x86_64-linux-gnu/sys/types.h:typedef __u_short u_short;
/usr/include/rpc/types.h:typedef __u_short u_short;
/usr/include/linux/coda.h:typedef unsigned short u_short;

# OS X
$ grep -IR "u_short" /usr/include | grep typedef
/usr/include/netinet/ip_mroute.h:typedef u_short vifi_t;        /* type of a vif index */
/usr/include/netinet6/ip6_mroute.h:typedef u_short mifi_t;      /* type of a mif index */
/usr/include/sys/types.h:typedef    unsigned short      u_short;

# Solaris
$ /usr/gnu/bin/grep -IR "u_short" /usr/include/ 2>/dev/null | grep typedef
/usr/include/sys/types.h:typedef unsigned short u_short;
/usr/include/rpcsvc/nfs_acl.h:typedef u_short o_mode;

You should be safe with a cast to unsigned short or perhaps a uint16_t (on Unix and Linux from <stdint.h>) rather than u_short.

于 2016-06-13T03:45:11.957 回答