0

What is syntax of far function pointer and what is use of "far" in below statement in c language given below? Why far is used in his statement ?

int (far *directCall_setBank)(void);

int VBE_getModeInfo(short mode) {
    VBE_ModeInfoBlock modeInfo;  //Temporary holding space for returned VBE info

    REGS r;        //Register structures for passing to 'int86x()'
    SREGS s;       //(SREGS includes the segment registers)

    r.x.ax=0x4F01; //AL = 0x01, "get VBE Mode Info"
    r.x.cx=mode;   //CX = mode to get info for
    r.x.di=FP_OFF(&modeInfo);   //address ES:DI to our ModeInfoBlock structure
    s.es=FP_SEG(&modeInfo);     //so that the VBE driver will fill its values

    int86x(0x10,&r,&r,&s); //call interrupt 0x10 (through a C function call)

    screen_width=modeInfo.resX;    //Store the values returned in
    screen_height=modeInfo.resY;   //'modeInfo'
    directCall_setBank=modeInfo.winFuncPtr; //INCLUDING the pointer to our function
    return((int)r.h.ah); //Return the VBE status in AH
}
Lanorkin
  • 7,310
  • 2
  • 42
  • 60

1 Answers1

2

It was used in dos era and very machine specific (memory model). To keep the C independent of specific architecture, C never accepted far keyword in standard language still it is available as extensions with some compilers.

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
  • If the code he posted is the actual code he's asking about: his argument declaration is `far *derectCall_setBank`. In which case, the argument is a pointer to a type named `far`, defined by either a `class`, `struct`, `union`, `enum` or `typedef`. For the memory model modifiers, the syntax would be `MyType far* directCall_setBank`. (Given the `FP_OFF` and `FP_SEG` later, I suspect that he's just miscopied something, and that your explication is the correct one.) – James Kanze Nov 07 '14 at 13:57
  • what my question is that in code given below void(far * ptr)(void) is it syntace for function pointer in which ptr is function pointer – Niravsinh Parmar Nov 09 '14 at 18:43
  • `http://cdecl.ridiculousfish.com/?q=int+%28*directCall_setBank%29%28void%29%3B` means [directCall_setBank is a pointer to function accepting (void) no arguments returning int](http://cdecl.ridiculousfish.com/?q=int+%28*directCall_setBank%29%28void%29%3B). `far int (*directCall_setBank)(void);` declares `directCall_setBank as far pointer to function (void) returning int`. `int (far *directCall_setBank)(void);` is incorrect syntax and hence will cause a compile time error even on extensions that support `far` keyword. – Mohit Jain Nov 10 '14 at 05:18