User`s guide
5 Controlling Code Generation
5-50
Naming the Print Handler Initialization Routine in C. Whenyouwritetheprinthandler
initializatio n routine in C, you m ust f ol low the naming conv enti on used by t he
MATLAB C Math Lib rary . T hi s na m e wil l ap p ear in a hea d er fil e t hat i s
generated by the MATLAB Compiler when it compiles the stub M-function,
initprnt in this example. See the earlier section, “Interfacing M-Code to C/
C++ Code,” for more information.
You should i nclude this Compiler-generated header file when y ou define the C
function. For ex ample , the print handler initia lizat ion ro uti ne deve lo ped h ere
is called
MInitprnt and is f ound in mr_external.h.
Naming the Dummy Print Handler Initialization Routine in M-Code. When you name the
dummy print ha ndler initializ ation routine in M-code, you must name it after
the base part of the act ual print hand ler init iali zati on ro utine (t he one writ te n
in C or C + +).
For exampl e, the dummy print handler init iali zati on ro utine s how n he re is
called
initprnt.
Writing the Initialization Routine in C. First, wr ite the print handler initialization
routine in C. All print handle r initialization functions r egiste r the name of t h e
printhandler function by calling
mlfSetPrintHandler, passinga pointer tothe
print handler (the function name) as an argument.
Your initialization f unction must take no arguments and return
void.For
exampl e,
void Mmr_initprnt(void)
{
mlfSetPrintHandler(myPrintHandler);
}
The file myph.c contains this code.
Writing a Dummy Initialization Function in M-Code. Next, write the dummy print
handler initi alization routine in M - cod e . T he body o f this f unctio n is e mpt y , but
without the function declarat ion, the MATL AB C o m piler can’t succe ssfully
translate the call to
initprnt in M-code into a call to MInitprnt() in C.
The function canbeplaced in the same M-file that define s th e main
mr.m inthis
example. It is declar ed as
function initprnt and contains the %#external
pragma.