Click here to Skip to main content
15,887,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C
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;
      }


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:

C
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;
      }
Posted
Updated 26-Oct-16 20:22pm
v3

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.
 
Share this answer
 
Comments
neor007i 27-Oct-16 23:00pm    
again the type modifiers are used with normal variables and NOT WITH POINTERS.
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.
 
Share this answer
 
Comments
neor007i 27-Oct-16 22:58pm    
#include<stdio.h>
int main(){
char far *p =(char far *)0x55550005;
char far *q =(char far *)0x53332225;
*p = 80;
(*p)++;
printf("%d",*q);
return 0;
}
neor007i 27-Oct-16 22:59pm    
Like i said far pointers are allowed within stack segment but when I used far with a normal variable not of pointer type, error generates.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900