16 bit compilers like Turbo C++ or Borland C++ have different types of pointer variables depending on the memory model of the compilation/linking. x86 processor points a memory location by a combination of segment registers and offset registers. Both registers are 16 bits wide. Now effective address is calculated by
Effective Address = (Segment Reg. << 4) + (Offset Reg.)
Near pointer: Near pointer is 16 bits wide and holds only offset address. This can point upto 64kb or 0xFFFF offset in a given segment.
int i = 0;
int * i_pointer = &i;
Far pointer: Far pointers are 32 bits wide and hold both 16bit segment and 16bit offset addresses. Thus a far pointer can point to any segment and to any offset inside that segment. MK_FP is a compiler macro which take segment and offset values and constructs a far pointer.
int far * i_pointer = (int far * )MK_FP(0xA000, 0);
i_pointer can have offset values from 0 to 0xFFFF.
Thus, it can access address inside range 0xA0000 to 0xAFFFF
Huge pointer: Huge pointers are also far pointers i.e. 32 bit pointers. The difference is that compiler rounds off the offset of a far pointer to zero when the offset reaches 0xFFFF but for a huge pointer, it increments the segment value on reaching 0xFFFF. Thus huge pointers can be increased or decreased uniformly between any segments and can have any value from 0 to 1MB.
char huge * i_pointer = (char huge * )MK_FP(0xA000, 0xFFFF);
In case of far pointers, increment of i_pointer will round it off to 0xA0000. But for huge pointers, the value will point to the next segment i.e. 0xAFFFF + 1 = 0xB0000.
Similar topics related to this section
structured programming language, first C program, header files, library, compilation, pre-processing, compilation, optimization, linking format, debugging with GDB, data types, storage classes, if, if-else, if-else-if, label and goto, switch case, loop statements, break and continue, pointers, enum type, macro, basic operators, logical operators, logical vs bitwise operators, bit shifting, Operator precedence, array, multidimensional arrays, user defined types, typedef, struct type, union type, struct vs union, struct pack padding, bit fields, structure as function argument, array as function argument, printing pointers, scanf string input, scan string with blanks, scanf string ends with newline, return of scanf, return of printf, scanf with printf, print using fprintf, take input using fscanf, floating point formatting, multiple arguments in printf and scanf, variadic functions, variadic macro, calling conventions, calling convention of C,C++ and PASCAL, operator precedence, ternary operator, switch statement, continue in switch and loops, for, while, do-while loop syntax, for to while, do-while and while usage, infinite loops, function declaration and definition, library function linking, call-by-value and call-by-reference, parameter passing call-by-value, parameter passing call-by-reference, address of local and dynamic variable, volatile variable, external vs static, global vs static variable, register vs auto variable, macro vs constant, debug builds, debug macros, compiler macro for C++, FILE, LINE, DATE, TIME, compiler marcos, token pasting, characterizing, char array and char pointers, enum vs macro, write vs append mode, binary vs text mode, macro vs typedef, size of a structure, upper and lower 16bit of 32bit unsigned, near, far and huge pointer, typed pointers and void pointer, sizeof void, sizeof void and void pointer, operators for void pointer, l-value, struct and array, NULL pointer, inline-functions, macro vs inline-function, malloc vs calloc, function pointer, compare with ==, argc and argv, C startup routine, strcpy and strcat source, signed and unsigned compare, string vs integer pointer, xor operator, bitwise shifting, logical and bitwise or, macro definition, long pointer increment, default C++ argument value, short pointer increment, execution sequence, exceptions, setjump and longjump, trace a memory leak, detect memory corruption, C and Data Structures, Data Structures using array, Linked List, Single Linked list, Doubly Linked list, Circular Linked list, Doubly Circular Linked list, Queue, Stack, Tree and Binary tree, heap, Complexity, Linear Search, Binary Search, Hash Table, Sorting, Bubble Sort, Selection Sort, Insertion Sort, Quick Sort, Heap Sort, Merge sort, Radix Sort, Recursion, argv environ, system(),
C/C++ Interview questions and answers - Shetty's World
C Interview Questions and Answers - C Interview FAQs & C Books
C interview questions and answers | TechInterviews
C Interview Questions and Answers :: ALL Interview .com
C Interview Questions and Answers
| #1 webmaster Sat 01 Feb/2014 17:50:54(GMT) || 0 || 0|
We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.
Your message goes here: