ARM Technical Support Knowledge Articles

INDIRECT FUNCTION CALL SYNTAX

Applies to: General Topics

Answer


Information in this article applies to:


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.

Article last edited on: 2004-06-10 17:06:40

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential