Keil Logo

GENERAL: INDIRECT FUNCTION CALL SYNTAX


Information in this article applies to:

  • C166 Version 3.12
  • C166 Version 4.03
  • C251 Version 2.14
  • C51 Version 5.50

QUESTION

I have noticed that functions can be called indirectly using the following syntax:

(*ptr)();

and:

ptr();

Is there a difference between the two methods? Should I use one in favor of the other? Will one of them cause any problems? Is this a mistake in the compiler?

ANSWER

Both methods are legal. The method that uses the indirection operator is the older one and ANSI C supports that method for purposes of compatibility with older compilers.

The following is the assembly code generated by the C51 compiler for both methods:

                 93   1        fptr();
0000 AA00    R     MOV     R2,fptr+01H
0002 A900    R     MOV     R1,fptr+02H
0004 120000  E     LCALL   ?C?ICALL
                 94   1        (*fptr)();
0007 AA00    R     MOV     R2,fptr+01H
0009 A900    R     MOV     R1,fptr+02H
000B 120000  E     LCALL   ?C?ICALL

As you can see, they are identical. The choice of which method to use is a personal preference.

Last Reviewed: Thursday, June 10, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.