INF: Getting the Address of a Function with FP_SEG and FP_OFF

ID Number: Q35295

3.00 4.00 5.00 5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

In Microsoft C versions 5.0, 5.1, 6.0, 6.0a, 6.0ax, and C/C++ version

7.0, to get the segment and offset of a function named func, declare a

pointer to a function, assign func to that pointer, and use FP_SEG and

FP_OFF to get the segment and offset from the pointer.

More Information:

The following sample code demonstrates this process:

Sample Code

-----------

/* Compile options needed: none

*/

#include <dos.h>

#include <stdio.h>

int func( void );

int (*func_ptr)();

unsigned int seg_val;

unsigned int off_val;

void main( )

{

/* set the pointer to the function */

foo_ptr = foo;

/* use FP_SEG() and FP_OFF() to get segment and offset */

seg_val = FP_SEG(foo_ptr);

off_val = FP_OFF(foo_ptr);

printf( "Segment is %d\nOffset is %d\n", seg_val, off_val );

}

int func()

{

}

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax 7.00