wtf是这个? [英] wtf is this?

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

问题描述

这是我第一次看到这样的代码而且我不知道这意味着什么

。它似乎是C代码,但我认为我很熟悉

大多数构造......一定是错过了一个:


u_char c_perm:3;


这个声明是在一个结构内部以及以类似方式声明的其他几个

变量。


我是假设u_char是unsigned char的typedef,但是什么是

" :3部分在那里做什么,这是什么意思?这是来自

C99的新语法还是一直存在,我以前从未碰到过它?


我在Xok exokernel中找到了这段代码麻省理工学院如果它产生差异或

你很好奇。


谢谢,

NR

This is the first time I have seen code like this and I don''t know what
it means. It appears to be C code but I thought I was familiar with
most constructs...must have missed one:

u_char c_perm : 3;

This declairation is inside of a struct along with several other
variables declaired in a similar manner.

I am assuming u_char to be a typedef for unsigned char, but what is the
" : 3" part doing there and what does it mean? Is this new syntax from
C99 or has it always been around and I just never ran into it before?

I found this code in the Xok exokernel from MIT if it makes a diff or
you are curious.

Thanks,
NR

推荐答案

Noah Roberts写道:
Noah Roberts wrote:
这是我第一次看到这样的代码,我不知道是什么这意味着。它似乎是C代码,但我认为我熟悉大多数构造......一定是错过了一个:

u_char c_perm:3;
This is the first time I have seen code like this and I don''t know what
it means. It appears to be C code but I thought I was familiar with
most constructs...must have missed one:

u_char c_perm : 3;




你不要问,直到你确定你找不到答案然后你会这样做:你真的知道这是什么我只是没见过它

使用了所以忘了它。我从来没有真正看到使用

位域的代码,这并不是唯一奇怪的事情:

/ *七个数组(7 - I ''作弊)字节命名能力如果

*它不是指针:* /

u_char c_name [1];

/ *如果这是一个指针,能力列表的长度和地址:* /

u_short cl_len;

struct Capability * cl_list;


当然这段代码并不是完全可移植的:P


NR



You hold off asking until you are sure you can''t find the answer and
then you do :P I actually knew what this was I just hadn''t ever seen it
used so forgot all about it. I have never actually seen code that used
bitfields, and that isn''t the only strange thing it does:
/* An array of seven (7--I''m cheating) bytes naming the capability if
* it is not a pointer: */
u_char c_name[1];
/* The length and address of the capability list if this is a pointer: */
u_short cl_len;
struct Capability *cl_list;

Of course this code is not meant to be exactly portable :P

NR


" Noah Roberts < NR ****** @ dontemailme.com>在消息中写道

news:bl ********** @ quark.scn.rain.com ...
"Noah Roberts" <nr******@dontemailme.com> wrote in message
news:bl**********@quark.scn.rain.com...
Noah Roberts写道:
Noah Roberts wrote:
这是我第一次看到这样的代码而且我不知道它意味着什么。它似乎是C代码,但我认为我很熟悉
大多数构造......一定是错过了一个:

u_char c_perm:3;
你推迟询问直到你肯定你找不到答案然后你会这样做:PI实际上知道这是什么我只是没见过>
This is the first time I have seen code like this and I don''t know what
it means. It appears to be C code but I thought I was familiar with
most constructs...must have missed one:

u_char c_perm : 3;
You hold off asking until you are sure you can''t find the answer and
then you do :P I actually knew what this was I just hadn''t ever seen it >



使用所以忘记了一切。我从来没有真正看到使用过bitfields的代码,这并不是唯一奇怪的事情:


你觉得奇怪的是什么?


/ *七个(7个我作弊)字节的数组命名能力,如果
*它不是一个指针:* /
u_char c_name [1];


这是*一个*类型''u_char''对象的数组。

/ *能力列表的长度和地址,如果这个是一个指针:* /
u_short cl_len;
struct Capability * cl_list;

当然这段代码并不是完全可移植的:P


used so forgot all about it. I have never actually seen code that used bitfields, and that isn''t the only strange thing it does:
What do you find strange?


/* An array of seven (7--I''m cheating) bytes naming the capability if
* it is not a pointer: */
u_char c_name[1];
That''s an array of *one* type ''u_char'' object.
/* The length and address of the capability list if this is a pointer: */
u_short cl_len;
struct Capability *cl_list;

Of course this code is not meant to be exactly portable :P




如果''u_char''和''u_short''是标准

类型的typedef,那么是的,它是可移植的。


-Mike



If ''u_char'' and ''u_short'' are typedefs for standard
types, then yes, it''s portable.

-Mike




" Noah Roberts" < NR ****** @ dontemailme.com>在消息中写道

news:bl ********** @ quark.scn.rain.com ...

"Noah Roberts" <nr******@dontemailme.com> wrote in message
news:bl**********@quark.scn.rain.com...
这是我第一次有看到这样的代码,我不知道它意味着什么。它似乎是C代码,但我认为我熟悉大多数构造......一定是错过了一个:

u_char c_perm:3;

这个声明是一个结构体内部以及以类似方式声明的其他几个变量。

我假设u_char是unsigned char的typedef,但是什么是
" :3部分在那里做什么,这是什么意思?这是来自C99的新语法还是一直存在,我以前从未碰到它?
This is the first time I have seen code like this and I don''t know what
it means. It appears to be C code but I thought I was familiar with
most constructs...must have missed one:

u_char c_perm : 3;

This declairation is inside of a struct along with several other
variables declaired in a similar manner.

I am assuming u_char to be a typedef for unsigned char, but what is the
" : 3" part doing there and what does it mean? Is this new syntax from
C99 or has it always been around and I just never ran into it before?




它已经存在了很长一段时间。查找''bitfield''。


-Mike



It''s been around quite a while. Look up ''bitfield''.

-Mike


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

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