HPlogo HP-UX/HP C Compiler: HP C/HP-UX Reference Manual > Chapter 11 Using Intrinsics

INTRINSIC Pragma

» 

Technical documentation

Complete book in PDF

 » Table of Contents

The INTRINSIC pragma allows you to declare an external function as an intrinsic. This pragma has the following format:

#pragma INTRINSIC intrinsic_name1 [user_name] [,intrinsic_name2 [user_name]]...

where:

intrinsic_name

is the name of the intrinsic you want to declare.

user_name

is a valid C identifier. If specified, you can use this name to invoke the intrinsic from the source program.

Examples

#pragma INTRINSIC FOPEN
#pragma INTRINSIC FCLOSE myfclose
#pragma INTRINSIC FCHECK, FGETINFO
#pragma INTRINSIC FWRITE mpe_fwrite, FREAD mpe_fread

The first example shows how to declare the FOPEN intrinsic. The second example shows how to declare FCLOSE; you must call it by the name myfclose in your program. The third and fourth examples each declare two intrinsics. The fourth provides alternative names for the intrinsics.

When you designate an external function as an intrinsic, the compiler refers to a special file (called an intrinsic file) to determine the function type, the number of parameters, and the type of each parameter. The compiler then uses this information to perform the necessary conversions and insertions to invoke the routine, or to issue warnings and errors if proper invocation is not possible.

Specifically, for intrinsic calls, the HP C compiler does the following:

  • Converts all value parameters to the type expected by the intrinsic function. Conversions are performed as if an assignment is done from the value to the formal parameter. This is known as assignment conversion. If a value cannot be converted, an error message is issued.

  • Converts addresses passed as reference parameters to the proper address type. This essentially means that short addresses are converted to long addresses as required by the intrinsic function. An integer value of zero is considered a legal value (NULL) for any address parameter.

  • Allows missing arguments in the call to the intrinsic if the intrinsic defines default values for those parameters. The compiler supplies the default values for the missing arguments, or issues a diagnostic if there is no defined default value. Missing arguments are allowed within an argument list or at the end of an argument list.

  • Issues an error message if there are too many arguments.

  • Inserts "hidden" arguments required by Pascal routines that have ANYVAR parameters (size is hidden), or that are EXTENSIBLE (parameter count is hidden). See the HP Pascal Programmer's Guide for more information.

Remember that C does not normally do any parameter counting, converting, or checking. So, if you attempt to declare an intrinsic using a standard C declaration rather than using the #pragma INTRINSIC statement, none of the above checks, conversions, or insertions are done. The address of an intrinsic can be taken, but if a call is made using a pointer to the intrinsic, the above checks are not performed. The intrinsic call then degenerates into a normal C function call.

To ensure that all calls are handled as expected, the intrinsic pragma should declare the name of the intrinsic using an identifier with the identical case that is used by the function calls in the program, especially if the optional user name is not specified. No other functions in the program should have the same name as any intrinsic that is declared, regardless of the case. This is because the actual run time symbol used to call an intrinsic is not necessarily the same case as the identifier used to declare that intrinsic.

© Hewlett-Packard Development Company, L.P.