Reputation: 9
I came across this code, where a macro called "small"
was defined and this macro has been used between the data type 'int'
and the variable Number
. I notice such a usage of words like "far" etc when declaring some pointers. What is the use of such a macro(keywords)? The same program works without the macro called "small".
#include <stdio.h>
#define small
int main(void) {
int small* Number ;
int x;
x=5;
Number = &x;
printf("The Number stored by x is : %d\n",*Number);
return 0;
}
Upvotes: 0
Views: 80
Reputation:
To answer your question about small
:
#define small
There is nothing after the small in the macro definition, so the preprocessor just replaces the empty macro with nothing.
int small* Number;
Expands to:
int *Number;
Upvotes: 0
Reputation: 79
It's a remainder from times when systems were not 32-bits and required something known as far-pointers in order to access addresses over 65535. Nowadays, the "far" macro evaluates to nothing.
However, if you would like to know how far pointers were implemented, one way they could be implemented was as a pointer to a pointer (that way, memory was treated as an array of 65k chunks).
Also note that macros, and anything else that can be defined by a programmer in C code, are not keywords. Only words such as int, short, const, etc. are keywords in C.
Upvotes: 1