home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Meridian Ada / Microsoft C Mixed Language Interface
- ---------------------------------------------------
-
-
- ( Note that versions 5.0 and 5.1 of the Microsoft C
- product were used in developing this capability. )
-
- These notes provide additional information regarding the
- use of Microsoft C code with Ada programs. Please read
- the Ada Compiler User's Guide and associated Release Notes
- before reading this material. This information is
- particularly important if you want to use any part of the
- Microsoft C run-time library and/or floating point data types
- within Microsoft C code.
-
-
- ===================================
- Initial Setup and Sample Programs
- ===================================
-
- In order to be able to more fully utilize Microsoft C
- compiled routines and its associated run-time support with
- Ada programs, the following procedures should be followed:
-
- 1. Install the Microsoft C library which uses the large
- memory model and the 80x87 coprocessor for floating point
- support. This library is normally called LLIBC7 and is
- normally located in the file \MSC\LIB\LLIBC7.LIB. Note
- that the provided batch files will need to be modified if
- the Microsoft C product is not installed in its normal
- place.
-
- 2. Make a modified Microsoft C library which is compatible
- with the Ada run-time by running the supplied batch file
- MAKELIB.BAT. This will delete certain incompatible
- start-up object modules from LLIBC7 and replace them with
- Ada-specific start-up modules. Note that the modified
- library is placed in the file ADALIBC7.LIB and that the
- original library is unchanged.
-
- 3. In the Ada program which interfaces to Microsoft C code,
- include a call to the Microsoft C function MSC_START
- before calling any other Microsoft C functions. This will
- initialize the Microsoft C run-time. Also, at the end of
- the Ada program (or at least after calling the last
- Microsoft C function) include a call to the Microsoft C
- function MSC_END to terminate the Microsoft C run-time.
-
- 4. Compile and link the Ada and Microsoft C code as described
- in the User's Guide but be sure to link the code with the
- modified Microsoft C library ADALIBC7.LIB. If in the link
- step, a Microsoft C library module is found to have
- undefined external references, then use of the module is
- most likely incompatible with the Ada runtime and should
- be removed.
-
-
- Included with this release are some sample Ada and Microsoft C
- programs which illustrate the use of pragma interface(Microsoft_C)
- and the above run-time interfacing procedures. These programs are
- called MSCTEST.ADA, CINTTST.C and CFLTTST.C. After running
- MAKELIB and creating an Ada program library with NEWLIB, simply
- run the batch file MAKEMSC to compile and link these programs.
- Note the definitions of and the placement of the calls to
- MSC_START and MSC_END in the Ada program. Also note in the
- CFLTTST.C program that Ada floating point data items must be
- defined as "double" in Microsoft C. There is no support for
- 32-bit floating point values in Ada programs.
-
-
- ==================================================
- Meridian Ada vs. Microsoft C Memory Model Issues
- ==================================================
-
- Normally, when a Meridian Ada program is produced, the Global
- Data Segment (pointed to by the DS register) and the Stack
- Segment (pointed to by SS), occupy separate segments of up
- to 64K each. This memory model is different from that of the
- standard Microsoft C model in which the Stack and Data
- Segments must fit into the same 64K segment and in which DS
- and SS have the same value. For most Microsoft C code, this
- difference is transparent to the program. However, there are
- some Microsoft C run-time functions which depend on this
- aspect of the memory model. It is important to be aware of
- these issues when developing Meridian Ada programs which
- interface to the Microsoft C run-time.
-
- To more fully accomodate the Microsoft C run-time functions an
- option is available to build a Meridian Ada/Microsoft C program
- which uses Microsoft C's standard memory model for combined
- Stack and Data Segments. To enable this option you must link
- in the object file MSCRTIO.OBJ from the Ada compiler's MSC
- subdirectory into your program. For example:
-
- ada example.ada
- auglib example c:\ada\msc\mscrtio.obj
- bamp -r example
- cl /AL /Gs /c cexample.c
- link /nod example cexample,,,adalibc7
-
- This special object file will then cause the Ada run-time to setup
- its SS and DS segment registers so that they have the same value.
-
- NOTE: If the amount of global data in your program plus the size
- the program's stack (as specified by the bamp -M and bamp -s
- options, or their default values) exceeds 64K, then the Stack
- and Data Segments cannot be combined and your program will
- abort at run-time with exit code 16. Therefore, you should
- try not to declare large data objects in Ada library packages
- or subprogram locals. Instead, you should allocate these
- from the heap (with new).
-
- NOTE: This capability is only available for real mode programs.
- You cannot use it in extended (or protected) mode programs.
-
-
- =========================================
- Microsoft C Run-Time Environment Issues
- =========================================
-
- A number of the Microsoft C run-time functions require information
- about the DOS environment variables such as PATH or COMSPEC. The
- original Microsoft C run-time code for accessing and maintaining
- these variables is incompatible with the way the Meridian Ada run-
- time currently operates. To better accomodate the Microsoft C
- run-time, an implementation of the C getenv() funtion which works
- with the Meridian Ada run-time, is included. This function is
- provided only in C source form in the file GETENV.C in the Ada
- compiler's MSC subdirectory. As such, you may modify it to meet
- your particular application's needs, compile it and link it into
- your program.
-
- Note that the substitute getenv has a maximum number of environment
- variables that it will support. Also, note that getenv() must be
- called to properly initialize the Microsoft C _environ variable
- which may be used by other Microsoft C functions. This getenv()
- also declares the __child Microsoft C variable which may be useful
- if you discover that this variable is undefined when you link your
- program.
-
-
- =====================================================
- Meridian Ada vs. Microsoft C Run-Time Compatibility
- =====================================================
-
- The following table lists those Microsoft C functions which have
- been tested with the Meridian Ada run-time and notes the degree
- to which each function is deemed compatible with Ada. Those
- functions listed as "Ok" worked with Ada programs regardless of
- whether the Stack and Data Segments were combined. Some of the
- "Ok" functions require the special version of getenv(). Those
- functions noted as "NOT compatible with Ada" failed to work (at
- least under some circumstances) in either case. The rest of the
- functions only work if the Stack and Data Segments are combined.
-
- Note that the testing performed did not necessarily exercise all
- aspects of the C functions, so it is possible that some of the "Ok"
- functions will fail under certain circumstances.
-
-
- Function Compatibilty
- -------------------------------------------------------------------
- access Ok
- assert NOT compatible with Ada (if it fails)
- atexit Ok
- atof Ok
- atoi Ok
- -------------------------------------------------------------------
- atol Ok
- _bios_disk Ok
- _bios_equiplist Ok
- _bios_keybrd Ok
- _bios_memsize Ok
- -------------------------------------------------------------------
- _bios_timeofday Ok
- chdir Requires combined Stack and Data
- close Ok
- creat Ok
- ctime Ok
- -------------------------------------------------------------------
- _dos_findfirst Ok
- _dos_findnext Ok
- fclose Ok
- feof Ok
- fflush Ok
- -------------------------------------------------------------------
- _ffree Ok
- fgetc Ok
- fgets Ok
- _fmalloc Ok
- fmod Requires combined Stack and Data
- -------------------------------------------------------------------
- fopen Ok
- fprintf Ok
- fputc Ok
- fputs Ok
- fread Ok
- -------------------------------------------------------------------
- free Ok
- fscanf (no floats) Ok
- " (with floats) Requires combined Stack and Data
- fseek Ok
- ftell Ok
- ftime Ok
- -------------------------------------------------------------------
- funlink Ok
- fwrite Ok
- getch Ok
- getcwd Requires combined Stack and Data
- getenv Ok, but needs new getenv()
- -------------------------------------------------------------------
- getpid Ok
- int86 Ok, as long as do not depend on DS == SS,
- else requires combined Stack and Data
- int86x Ok
- intdos Ok, as long as do not depend on DS == SS,
- else requires combined Stack and Data
- isalnum Ok
- -------------------------------------------------------------------
- isalpha Ok
- isascii Ok
- isatty Ok
- iscntrl Ok
- isdigit Ok
- -------------------------------------------------------------------
- isgraph Ok
- islower Ok
- isprint Ok
- ispunct Ok
- isspace Ok
- -------------------------------------------------------------------
- isupper Ok
- isxdigit Ok
- kbhit Ok
- localtime Ok
- locking Ok
- -------------------------------------------------------------------
- log Requires combined Stack and Data
- lseek Ok
- malloc Ok
- memcmp Ok
- memmove Ok
- -------------------------------------------------------------------
- memset Ok
- mkdir Ok
- mktemp Ok
- open Ok
- _osmajor Ok
- -------------------------------------------------------------------
- printf Ok
- raise NOT compatible with Ada
- read Ok
- realloc Ok
- rename Ok
- -------------------------------------------------------------------
- rmdir Ok
- signal Ok, but needs new getenv()
- _splitpath Ok
- sprintf (no floats) Ok
- " (with floats) Requires combined Stack and Data
- sscanf Ok
- -------------------------------------------------------------------
- stat Requires combined Stack and Data
- strcat Ok
- strchr Ok
- strcmp Ok
- strcpy Ok
- -------------------------------------------------------------------
- stricmp Ok
- strlen Ok
- strncat Ok
- strncmp Ok
- strncpy Ok
- -------------------------------------------------------------------
- strnicmp Ok
- strpbrk Ok
- strrchr Ok
- system Ok, but needs new getenv()
- tell Ok
- -------------------------------------------------------------------
- time Ok
- toascii Ok
- tolower Ok
- _tolower Ok
- toupper Ok
- -------------------------------------------------------------------
- _toupper Ok
- unlink Ok
- utime Requires combined Stack and Data
- write Ok
- -------------------------------------------------------------------
-
-
- =============
- END OF FILE
- =============
-