在C中使用类型修饰符(near,far,huge)和正常变量 [英] Use of type modifiers(near, far, huge) with normal variables in C

查看:188
本文介绍了在C中使用类型修饰符(near,far,huge)和正常变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用类型修饰符(far,near,huge)和普通变量而不是指针,发现这些指针类型修饰符仅适用于全局法线变量,但是当与块的局部变量一起使用时会产生错误。



I used type modifiers(far,near,huge) with normal variables rather than pointers and found that these pointer type modifiers are only applicable for the global normal variable but an error is generated when used with a variable local to a block.

int near a,far b,huge c;

    int main()
    {
      int d,e,f;
      printf("\n address of a=%u ,b=%u ,c=%u ,d=%u ,e=%u ,f=%u",&a,&b,&c,&d,&e,&f);
      return 0;
      }





为什么这个全局变量允许,而不是局部变量。另外,变量最终变成了什么,即变成指针,具有更大范围的整数或完全不同的东西。



问题已经发布超过一年 stackoverflow



我尝试过:





why is this allowed with a global variable and not with a local variable. Additionally, what does the variable finally becomes i.e. it becomes a pointer,an integer with greater range or entirely something else.

Question already posted for over a year on stackoverflow

What I have tried:

int near a,far b,huge c;

    int main()
    {
      int d,e,f;
      // int near a,far b,,huge c;
      // long int near a,far b,huge c;
      // long long int near a,far b,huge c;

      //printf("\n size of a=%d ,b=%d ,c=%d ,d=%d ,e=%d ,f=%d",sizeof(a),sizeof(b),sizeof(c),sizeof(d),sizeof(e),sizeof(f));
      printf("\n address of a=%u ,b=%u ,c=%u ,d=%u ,e=%u ,f=%u",&a,&b,&c,&d,&e,&f);
      return 0;
      }

推荐答案

这是编译器的旧关键字,用于增强指针地址模型。一个很好的解释是在 cplusplus-forum



在今天的编程世界中,这些关键字是不需要的。



有了一个小谷歌,你会在去年找到答案。与维基百科中的远指针的解释一样。
This are old keyword for compilers, to enhance the pointer address model. A good explanation is in the cplusplus-forum.

In today programming world these keywords arent needed.

With a little Google you would had found the answer in the last year. Like the explanation of the far pointer in the wikipedia.


使用了这些关键字在过去,内存被分段(代码段,数据段,堆栈段等)。

使用当前的虚拟内存模型,这些关键字并不重要。



但是为了回答你的问题,局部变量都存在于一个段(Stack)中,因此关键字不适用于它们。
These keywords were used in the old days when memory was segmented (Code Segment, Data Segment, Stack Segment etc.).
With the current Virtual Memory Model, these keywords are of no importance.

But to answer your question, local variable all reside in a single segment (Stack) and hence the keywords don't apply to them.


这篇关于在C中使用类型修饰符(near,far,huge)和正常变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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