HP 3000 Manuals

Calling MPE/iX Intrinsics [ HP C Programmer's Guide ] MPE/iX 5.0 Documentation


HP C Programmer's Guide

Calling MPE/iX Intrinsics 

MPE/iX offers a set of system-supplied procedures, known as intrinsics.
These intrinsics are callable from HP C. The tasks that intrinsics handle
include:

   *   Accessing and altering files (for example, writing to a file).
   *   Accessing system resources (for example, getting the system time).
   *   Process handling and interprocess communication.
   *   Issuing MPE/iX commands.
   *   Invoking the debugger.
   *   Getting and setting process table parameters (privileges,
       priorities).
   *   Allocating and deallocating memory.
   *   Setting error traps.

Many of the tasks performed by MPE/iX intrinsics can be performed by
using C library functions.  If you are programming for portability, you
should use the standard C Library functions whenever possible.  If you
are programming for performance, you can call MPE/iX intrinsics directly
rather than accessing them through the C libraries.


NOTE Do not mix C Library input/output functions with MPE/iX file system intrinsics in the same program. You can get unpredictable results.
Specifying the Intrinsic Pragma The intrinsic intrinsic_name pragma facilitates calling MPE/iX intrinsic procedures. This pragma directs the compiler to check the syntax of intrinsic calls in your source file. It enables the compiler to automatically provide default values for missing optional parameters, and to perform data type conversions if necessary. The syntax for the intrinsic pragma is: #pragma intrinsic intrinsic_name where intrinsic_name is the name of a system-supplied procedure. These procedures are documented in the MPE/iX Intrinsics Reference Manual. Calling HPFOPEN. The following example uses the intrinsic pragma and sets up the call to HPFOPEN: #pragma intrinsic HPFOPEN main(void) { : HPFOPEN ( &file_num, &status, file_name, &fname, access, &file_access, domain, &file_domain); : } Declaring MPE/iX Intrinsics as External Functions. It is possible to call MPE/iX intrinsics by declaring the procedures as external functions. However, you will then need to know the exact calling sequence. If you declare MPE/iX intrinsics as extern, you need to pass the correct number of parameters, and then pass them with the correct data type. Using the intrinsic pragma is the preferred method. It removes the burden of supplying the correct values for otherwise optional parameters, and for correctly handling intrinsics that can take a variable number of parameters. Sample Program Using MPE/iX File System Intrinsics In the following sample program, MPE/iX file system intrinsics perform the following tasks: * Create a new permanent variable record length ASCII file. * Write an 80 byte record to the file. * Close the file. * Reopen the file created previously. * Read the record that was written previously. * Close the file and exit the program. #include <mpe.h> #include <stdio.h> #include <stdlib.h> #pragma intrinsic FCHECK, FOPEN, FCLOSE, FWRITE, FREAD #pragma intrinsic HPFOPEN /* Message written to "mine" file */ char target[80] = "Record in `mine' file!\n"; char newtarg[80]; main(void) { int filenum; /* holds value returned by HPFOPEN */ int desig = 2; /* item number */ /* formal file name */ static char desig_file[]="%mine%"; int domain = 3; /* new file option */ int domain_perm = 1; int domain_create_perm = 4; int rec_format = 6; /* record format option */ int rec_format_op = 1; /* variable length record */ int type = 10; /* standard file type */ int type_std = 0; /* file type = STD */ int access = 11; /* access type */ int access_read = 0; /* open file for read access */ int access_writesave = 2; /* open file for write access, save as perm file */ int filesize = 35; /* file size option */ int filesize_op = 256; /* record size */ int ascii_bin = 53; /* file type: equals ASCII or binary */ int ascii_bin_file = 1; /* ASCII value */ short errnum; short len; struct{ short info; short subsys; }status; /* Create a new perm fixed rec length ASCII file */ HPFOPEN(&filenum,&status, desig, &desig_file, domain, &domain_create_perm, rec_format, &rec_format_op, type, &type_std, access, &access_writesave, filesize, &filesize_op, ascii_bin, &ascii_bin_file); if((status.info == 0 ) && (status.subsys == 0)) printf("Open worked!\n"); else { printf("Open failed.\n"); printf("%d\n%d\n",status.info,status.subsys); exit(1);} FWRITE(filenum,target,-80,0); if(ccode()!=CCE){ printf("Write failed.\n"); exit(1);} printf("Write worked!\n"); FCLOSE(filenum,1,0); if(ccode()!=CCE){ printf("Close failed.\n"); exit(1);} printf("Close worked!\n"); /* Open existing file for read only access. */ HPFOPEN(&filenum,&status,desig ,&desig_file, domain, &domain_perm, access, &access_read); if((status.info == 0 ) && (status.subsys == 0)) printf("Open worked!\n"); else { printf("Open failed.\n"); printf("%d\n%d\n",status.info,status.subsys); exit(1);} len=FREAD(filenum,newtarg,-80); if(ccode()!=CCE){ printf("Read failed.\n"); FCHECK(filenum,&errnum); printf("%d",errnum); exit(1);} printf("Read worked!\n"); printf("%s",newtarg); FCLOSE(filenum,0,0); if(ccode()!=CCE){ printf("Close failed.\n"); exit(1);} printf("Close worked!\n"); exit (0); } Figure 3-3. Calling MPE/iX Intrinsics Example


MPE/iX 5.0 Documentation