一个enum和ntoh的问题 [英] an enum and ntoh question

查看:114
本文介绍了一个enum和ntoh的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


如果我有一个枚举定义

例如


typedef enum {

F0 = 0,

F1 = 1,

F2 = 2,

F3 = 3

} Ftest;


Ftest a;

我需要做ntoh,哪一个使用ntohl或ntohs?


我是否必须将其强制转换为Ftest?


非常感谢!

解决方案

po *********** @ gmail.com 写道:

你好

如果我有一个枚举定义


typedef enum {
F0 = 0,
F1 = 1,
F2 = 2,
F3 = 3
} Ftest;

Ftest a;
我需要做ntoh,哪一个使用ntohl或ntohs?

我是否必须将它转回Ftest?




你的问题是关于主题,ntoh *()和hton *()函数不属于你的部分

of S标准C.


另外,你的问题似乎没有太好框架。


我想你问的可能是什么是`enum`的'type`。好吧,

标准指定它必须适合`int`。现在,查看你的函数声明如何
,你会弄清楚(或不知道)该做什么。

这似乎取决于你的大小`int`。


干杯


弗拉基米尔


-

如果只有我可以得到尊重而不必受到尊重。


po *********** @ gmail.com 写道:

#Hello



#如果我有枚举定义

#例如



#typedef enum {

#F0 = 0,

#F1 = 1,

#F2 = 2,

#F3 = 3
#} Ftest;



#Ftest a;

#我需要做ntoh,哪一个要使用ntohl或ntohs?


为什么猜?投下它,你不必担心。你用它做什么?

你需要长期或短期结果吗?


#我必须把它还给Ftest吗? />

Ftest只是另一个整数。


-

SM瑞恩 http://www.rawbw.com/~wyrmwif/

如果您打算购物,让我们知道。

谢谢


SM Ryan写道:

po *********** @ gmail.com 写道:
#Hello

#如果我有枚举定义
#例如

#typedef enum {
#F0 = 0,
#F1 = 1,
#F2 = 2,
#F3 = 3
#} Ftest;

#Ftest a;
#我需要做ntoh,哪一个使用ntohl或ntohs?

为什么猜?投下它,你不必担心。你用它做什么?
你需要长期或短期的结果吗?

#我必须把它还给Ftest吗?

Ftest是只是另一个整数。




不,它不是,它是一种名为`Ftest`的新类型,实际上是一个

`enum`。枚举可以表示为int的事实(因为标准

向我们保证)doe snot意味着enums / are / int。他们是一个完全不同的野兽。


干杯


弗拉基米尔


Hello

If I have an enum definition
for instance

typedef enum {
F0 = 0,
F1 = 1,
F2 = 2,
F3 =3
} Ftest;

Ftest a;
and I need to do ntoh, which one to use ntohl or ntohs?

And do I have to cast it back to Ftest?

Thanks a lot!

解决方案

po***********@gmail.com wrote:

Hello

If I have an enum definition
for instance

typedef enum {
F0 = 0,
F1 = 1,
F2 = 2,
F3 =3
} Ftest;

Ftest a;
and I need to do ntoh, which one to use ntohl or ntohs?

And do I have to cast it back to Ftest?



Your question is off topic, ntoh*() and hton*() functions not being part
of Standard C.

Also, your question does not seem to be too well framed.

What I think you''re asking may be what''s the `type` of an `enum`. Well,
the Standard specifies that it has to fit in an `int`. Now, look up how
your functions are declared, and you''ll figure out (or not) what to do.
It seems to depend on the size of your `int`.

Cheers

Vladimir

--
If only I could be respected without having to be respectable.


po***********@gmail.com wrote:
# Hello
#
# If I have an enum definition
# for instance
#
# typedef enum {
# F0 = 0,
# F1 = 1,
# F2 = 2,
# F3 =3
# } Ftest;
#
# Ftest a;
# and I need to do ntoh, which one to use ntohl or ntohs?

Why guess? Cast it and you don''t have to worry. What are you using it for?
Do you need a long or short result?

# And do I have to cast it back to Ftest?

Ftest is just another integer.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
If you plan to shoplift, let us know.
Thanks


SM Ryan wrote:

po***********@gmail.com wrote:
# Hello
#
# If I have an enum definition
# for instance
#
# typedef enum {
# F0 = 0,
# F1 = 1,
# F2 = 2,
# F3 =3
# } Ftest;
#
# Ftest a;
# and I need to do ntoh, which one to use ntohl or ntohs?

Why guess? Cast it and you don''t have to worry. What are you using it for?
Do you need a long or short result?

# And do I have to cast it back to Ftest?

Ftest is just another integer.



No, it''s not, it''s a new type called `Ftest`, which is actually an
`enum`. The fact that enums can be represented as ints (as the Standard
assures us) doe snot mean that enums /are/ ints. They''re a completely
different beast.

Cheers

Vladimir


这篇关于一个enum和ntoh的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆