Consulta (en espa~ol) (responder en ingles) 
Author Message
 Consulta (en espa~ol) (responder en ingles)

** High Priority **

On 25 Oct 1995 Paco said ... (my pidgin translation is included)

  >  Necesito conocer un peque~o detalle sobre el ADA, no creo que sea
  > demasiado complejo asi que agradeceria una respuesta (aunque no sea
  > completa).

   "I need to understand a few details about Ada, the answer does not have to be
    complex or complete."

  >  Quiero saber como se puede incluir codigo maquina (ensamblador) dentro
  > de un programa ADA o el modo de llamar a un modulo externo en otro
  > lenguaje.

  "I want to know how to include machine code (assembler) inside of an Ada
   program or a way to call an external module written in another language."

  > Me serviria con una indicacion o una referencia conocida.

  "I would prefer an example or a known reference."

Ada 95:
Reference: Annex B, Interface to Other Languages, Ada Reference Manual (ISO/IEC
"The Ada 95 LRM"  Also look at Sec 13.8 (System.Machine_Code) of the LRM and you
r compiler to
see if it supports package System.Machine_Code (and to what extent)

some combo of, System.Machine_Code, pragma Import, pragma Convention, and pragma
Linker_Options, and perhaps other compiler dependent pragmas

Ada 83:
Reference: Appendix B, Reference Manual for the Ada Programming Language (Mil-St
"The Ada 83 LRM"  Also look in Appendix F of your compiler's documentation.  Als
o look at
Sec 13.8 (Machine_Code) of the LRM and your compiler to see if it supports packa
Machine_Code (and to what extent)

Machine_Code, pragma Interface, pragma Interface_Name (on some compilers),
The linking part will be compiler/linker dependent. I've seen it done
via a pragma and I've seen it done as a switch to the linker

Suppose I've written a family of C functions.  I am interested in calling some
of this code from my Ada program.  My approach is to create an Ada package,
Do_Family, which interfaces to the object code living in dofamily.lib.

void doit (const char *str);  /* the C prototype in dofamily.h */

-- the Ada interface using VADS NT
-- your compiler may do it a different way
package Do_Family is
  procedure Do_It (To_A_String : in String);
end Do_Family;

with Unchecked_Conversion;
with System;
package body Do_Family is

  -- tell link where the object code lives
  -- your compiler/linker may do it a different way
  pragma Link_With ("dofamily.lib");

  -- C's native view of a string under Windows NT
  -- this has worked for me on many different compilers
  type Cstrptr is access Character;

  -- need to convert the address of the first character in a string
  -- into an access type so it can be sent directly to the thin C binding
  procedure Address_To_Cstrptr is new Unchecked_Conversion
     Source => System.Address, Target => Cstrptr);

  ---------------------  THIN BINDING ---------------------------
  -- the C-like thin binding is a direct interface to the C library routine
  procedure Do_It (To_A_String : in Cstrptr);

  -- use C calling convention
  pragma interface (C, Do_It);

  -- tell linker what the name looks like in the library file
  -- I've seen this work on several different compilers, however
  -- the "mangled name" in quotes varies from system to system

  ---------------------  THICK BINDING ---------------------------
  -- the Ada-like thick binding calls the thin binding
  procedure Do_It (To_A_String : in String) is

    Temp : constant String := To_A_String & Ascii.Nul;  -- C strings end with nu
ll byte

  begin -- Do_It

    -- we send the address of the first character of the null-terminated
    -- array of Characters (as an access type) to our thin binding, just like C
    Do_It(To_A_String => Address_To_Cstrptr(Temp(Temp'first)'address));

  end Do_It;

end Do_Family;

Hope this helps some...

Jerry Morris

Mon, 13 Apr 1998 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Consulta (en espa~ol)

2. A little page about J in Spanish / Una peque?a página de J en espa?ol

3. Página de programación para Mac en espa?ol


5. DOS ERROR 55 (En Espa?ol)

6. news en espa?ol sobre clipper

7. Clipper 5.2 - Información en espa?ol

8. Web en Espa?ol

9. necesito 5.3 en espa?ol

10. clipper en espa?ol

11. Necesito código fuente de un calendario pop-up ( en espa?ol )



Powered by phpBB® Forum Software