开发者

Simple Assignment

Here's my problem. I have the follow开发者_如何转开发ing structure defined

struct idt_reg{
  unsigned short limit;
  unsigned int base;
}__attribute__((packed));

In my code I do the following assignment

unsigned short num_ids = idtr.limit >> 3;

Now upon execution, when the value stored in idtr.limit is equal to 2047(0x7FF), what I expected to happen was a right shift of 3 bits (divide by 8) and get the value of 255 written to num_ids. Instead the value of num_ids is always 0.

Any help I would really appreciate.


This:

#include <stdio.h>

struct idt_reg{
  unsigned short limit;
  unsigned int base;
}__attribute__((packed));

int main() {
    struct idt_reg idtr;
    unsigned short num_ids;
    idtr.limit = 2047;
    num_ids = idtr.limit >> 3;
    printf( "%d\n", num_ids );
}

prints 255.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜