
Language Features
SC100 C Compiler
3-57
3.4.5.3.3 Defining a function as external
When the compiler encounters an unresolved function call, it assumes by default that this is a call to an
external function that exists outside the application. The pragma
#pragma
external
enables you to:
Confirm this assumption, by informing the compiler that the call is to an external function defined
outside the application
Define the function as an internal function that can be called from outside the application
The effect of the pragma depends on its placement, as described below:
If
#pragma
external
is specified in the global scope, the compiler does not expect to find the body
of the function within the current application. The compiler uses standard calling conventions to call
the function, and does not issue warnings for unresolved references. Specifying
#pragma
external
in the global scope is valid only in global optimization mode.
If
#pragma
external
is specified within the function scope, followed by the body of the defined
function, the compiler recognizes this as an internal function that can be called from outside the
application.
The following optional parameters can be specified with
#pragma
external
:
Specify
name
=
string
to provide a specific function name, to override the default linkage name
allocated to the function.
Define
convention
=
number
to select the calling convention to be used instead of the default
standard convention. See
Chapter 6,
“
Runtime Environment,
”
for further information about calling
conventions.
Specify
nosideeffects
if the function does not change any variable values in the application, and
can be moved or duplicated in other parts of the application without making any changes.
When
nosideeffects
is specified, the compiler does not need to make worst case assumptions about
any possible impact that the function may have within the application.
In the first part of Example 3-31,
printf
is defined as an external function that does not exist within the
application, and that has no effect on any variables in the application. In the second part of the example, the
function
ICanBeCalled
is defined inside the application and may be called by external function calls.
This function therefore has to obey the standard calling conventions.
Example 3-31. #pragma external
extern void printf();
#pragma external printf [nosideeffects]
void main()
{
printf("Hello there\n");
}
void ICanBeCalled(int X, int Y)
{
#pragma external ICanBeCalled [name ="xyz"]
...
}