Searching \ for '[EE] C and Pascal question' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'C and Pascal question'.

Exact match. Not showing close matches.
PICList Thread
'[EE] C and Pascal question'
2004\10\23@085020 by Omer YALHI

I have used EE for topic, please change it OT if you feel this does not
belong here.

I have a friend who is trying to access the IrDA port on a Radix unit, the
manufacturer sent him a C code example; however, he is coding in Pascal.  I
know C but not Pascal.  The C code uses function pointers and if there are
any ideas how to convert it to Pascal I will appriciate it.

This is the definitions:

enum {
   /* normal application use */

typedef int (FAR *FPI)();

static char sig[] = "RadixIrDA";
FPI comm_entry = 0L;

The FPI is giving him the trouble.  Below is the function to find the

* locate IrDA interrupt and save entry point in comm_entry
static int find_irda(void)
   int i;
   void FAR *p;
   char FAR *s;

   if (comm_entry != 0) return 1;      /* already located */

   for (i=0x60;i<=0x67;i++) {          /* else look for it */
       p = MAKEFAR(0,(i<<2));
       if ((s = *(char FAR * FAR *)p) != 0L) {
           if (!strcmpf(s+3,sig)) {
               comm_entry = (FPI)s;
               return 1;
   return 0;

The confusing lines are:

p = MAKEFAR(0,(i<<2));
if ((s = *(char FAR * FAR *)p) != 0L)

After this function is called, they use the following functions to access
the port:

int IrDA_open(void)
   if (find_irda()) {
       hport = comm_entry(C_OPEN);
   return hport;

int IrDA_recv(int portid,char *buffer,int len)
   if (portid != hport) return -1;
   return comm_entry(C_READ,portid,(char FAR *)buffer,len);

They are accesing the comm_entry with different number of parameters which
confuses him.  I have told him that comm_entry is a function pointer and the
first parameter points to the actual function, comm_entry is not a function
itself.  I hope this is correct.

Any pointers are appriciated,

Regards, Omer


2004\10\24@142822 by Bob Ammerman

picon face
The comments below assume that the "C" language environment is 16-bit
Microsoft or Borland C, and that the Pascal involved is a 16-bit real-mode
version of Borland/Turbo Pascal...

{Quote hidden}

The following loop is examining interrupt vectors looking for
{Quote hidden}

> p = MAKEFAR(0,(i<<2));

This is creating a pointer to the interrupt vector table entry for interrupt
number 'i'.

> if ((s = *(char FAR * FAR *)p) != 0L)

This is extracting the interrupt vector table entry and treating it as a
pointer to char. In reality, it is a pointer to the code located at the
interrupt vector.

> if (!strcmpf(s+3,sig)) {
>            comm_entry = (FPI)s;

If the memory starting 3 bytes beyond the code matches the signature, then
set 'comm-entry' to be a (far) pointer to the code. The first instruction is
probably a three byte jump instruction over the signature string.

{Quote hidden}

You are correct in that comm_entry is a function pointer. The "C"
declaration for that function pointer would be...

int (FAR *comm_entry) (int functioncode, ...);

This is a function that can accept a functioncode, followed by whatever
parameters are used by that function code.

You will have an issue with the different calling sequences of "C" and
"PASCAL" functions. The differences are the order in which arguments are
pushed on the stack, and  whether the caller or callee is responsible for
removing the parameters from the stack. You can build a set of 'shim'
functions in (inline) assembly to allow you to call the "C" functions out of

Bob Ammerman
RAm Systems


2004\10\25@041817 by Omer YALHI

Bob Ammerman,

Thank you for the reply.  It does give more detailed information about the C
code, and hopefully, make some sense to him so that the conversion can be

Regards, Omer


More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...