0

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;
}
Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33
  • https://stackoverflow.com/questions/3575592/what-are-near-far-and-huge-pointers – Mat Mar 11 '20 at 14:37
  • Take a look to https://stackoverflow.com/questions/13892191/are-empty-macro-definitions-allowed-in-c-how-do-they-behave – David Ranieri Mar 11 '20 at 14:38
  • what do you mean by `far`? It is not in your code? could you please be more clear? –  Mar 11 '20 at 14:47
  • What's the point in the small macro? it's empty, so it expands to nothing. –  May 14 '20 at 07:06
  • @asadefa : That was the whole point of my question , why such words are used between the datatype and the keyword. I have also given a reference to some popular words like far, near etc. – krishna1950 May 15 '20 at 08:05

2 Answers2

1

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.

cpp plus 1
  • 67
  • 9
  • 1
    In the days of 8086 programming, there were [small, medium, compact, large and huge models for memory](https://users.pja.edu.pl/~jms/qnx/help/watcom/compiler16/wmodels.html) — with small using it 16-bit pointers for data and code, with compact using 16-bit pointers for code and 32-bit (20-bit) pointers for data, with medium using 32-bit (20-bit) pointers for code and 16-bit pointers for data, and with large using 32-bit (20-bit) pointers for both code and data (and huge was similar to large, but handled segment overflows better). Remember: "640 KB ought to be enough for anyone"! – Jonathan Leffler Mar 11 '20 at 15:27
0

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;