comp.lang.ada
 help / color / mirror / Atom feed
* Interface with C codes
@ 2014-10-17 23:22 Anh Vo
  2014-10-17 23:30 ` Anh Vo
                   ` (3 more replies)
  0 siblings, 4 replies; 18+ messages in thread
From: Anh Vo @ 2014-10-17 23:22 UTC (permalink / raw)


What Ada spec should be for the following C prototype where BOOT_PARAMS is a struct and responding Ada type is

type Boot_Parameter_Type is
   record
      Boot_Dev : Interfaces.C.Strings.Chars_Ptr;
      -- ...
   end record;
pragma Convention (C, Boot_Parameter_Type);

type Boot_Parameter_Type_Access is access Boot_Parameter_Type;
pragma Convention (C, Boot_Parameter_Type_Access);


typedef struct           /* BOOT_PARAMS */
    {
    char bootDev [20];  /* boot device code */
    * ... *
    } BOOT_PARAMS;

Note that I can not use Ada 2012 yet.


char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams);


Anh Vo

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-17 23:22 Interface with C codes Anh Vo
@ 2014-10-17 23:30 ` Anh Vo
  2014-10-18 18:33   ` Stephen Leake
  2014-10-17 23:49 ` Adam Beneschan
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 18+ messages in thread
From: Anh Vo @ 2014-10-17 23:30 UTC (permalink / raw)


On Friday, October 17, 2014 4:22:15 PM UTC-7, Anh Vo wrote:
> What Ada spec should be for the following C prototype where BOOT_PARAMS is a struct and responding Ada type is
>  
> 
> type Boot_Parameter_Type is
> 
>    record 
>       Boot_Dev : Interfaces.C.Strings.Chars_Ptr; 
>       -- ... 
>    end record;
> 
> pragma Convention (C, Boot_Parameter_Type);
>  
> 
> type Boot_Parameter_Type_Access is access Boot_Parameter_Type;
> 
> pragma Convention (C, Boot_Parameter_Type_Access);
>  
> typedef struct           /* BOOT_PARAMS */ 
>     { 
>     char bootDev [20];  /* boot device code */ 
>     * ... * 
>     } BOOT_PARAMS;
>   
> Note that I can not use Ada 2012 yet.
>  
> char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams); 
 
> Anh Vo

Should this one work?

function Boot_String_To_Type (
           Boot_String : Interfaces.C.Strings.chars_ptr;
           Boot_Params : Boot_Parameter_Type_Access) 
                             return Interfaces.C.Strings.chars_ptr;
pragma Import (C, Boot_String_To_Type, "bootStringToStruct");

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-17 23:22 Interface with C codes Anh Vo
  2014-10-17 23:30 ` Anh Vo
@ 2014-10-17 23:49 ` Adam Beneschan
  2014-10-18  0:04   ` Anh Vo
  2014-10-18  2:20 ` Jeffrey Carter
  2014-10-18  6:27 ` Per Sandberg
  3 siblings, 1 reply; 18+ messages in thread
From: Adam Beneschan @ 2014-10-17 23:49 UTC (permalink / raw)


On Friday, October 17, 2014 4:22:15 PM UTC-7, Anh Vo wrote:
> What Ada spec should be for the following C prototype where BOOT_PARAMS is a struct and responding Ada type is
> 
> type Boot_Parameter_Type is
>    record
>       Boot_Dev : Interfaces.C.Strings.Chars_Ptr;
>       -- ...
>    end record;
> 
> pragma Convention (C, Boot_Parameter_Type);
> 
> type Boot_Parameter_Type_Access is access Boot_Parameter_Type;
> pragma Convention (C, Boot_Parameter_Type_Access);

> typedef struct           /* BOOT_PARAMS */
>     {
>     char bootDev [20];  /* boot device code */
>     * ... *
>     } BOOT_PARAMS;
> 
> Note that I can not use Ada 2012 yet.
> 
> char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams);
> 
> Anh Vo

I'm confused.  You've defined an Ada record Boot_Parameter_Type that has a pointer in it, and a C struct that does not have a pointer. 

                                -- Adam



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-17 23:49 ` Adam Beneschan
@ 2014-10-18  0:04   ` Anh Vo
  2014-10-18  1:04     ` Anh Vo
  2014-10-20 16:14     ` Adam Beneschan
  0 siblings, 2 replies; 18+ messages in thread
From: Anh Vo @ 2014-10-18  0:04 UTC (permalink / raw)


On Friday, October 17, 2014 4:49:04 PM UTC-7, Adam Beneschan wrote:
> On Friday, October 17, 2014 4:22:15 PM UTC-7, Anh Vo wrote:
> 
> > What Ada spec should be for the following C prototype where BOOT_PARAMS is a struct and responding Ada type is
> 
> > 
> 
> > type Boot_Parameter_Type is
> 
> >    record
> 
> >       Boot_Dev : Interfaces.C.Strings.Chars_Ptr;
> 
> >       -- ...
> 
> >    end record;
> 
> > 
> 
> > pragma Convention (C, Boot_Parameter_Type);
> 
> > 
> 
> > type Boot_Parameter_Type_Access is access Boot_Parameter_Type;
> 
> > pragma Convention (C, Boot_Parameter_Type_Access);
> 
> 
> 
> > typedef struct           /* BOOT_PARAMS */
> 
> >     {
> 
> >     char bootDev [20];  /* boot device code */
> 
> >     * ... *
> 
> >     } BOOT_PARAMS;
> 
> > 
> 
> > Note that I can not use Ada 2012 yet.
> 
> > 
> 
> > char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams);
> 
> > 
> 
> > Anh Vo
> 
> I'm confused.  You've defined an Ada record Boot_Parameter_Type that has a pointer in it, and a C struct that does not have a pointer. 
> 

The second parameter of the function prototype use pointer, BOOT_PARAMS * pBootParams.

Anh Vo


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-18  0:04   ` Anh Vo
@ 2014-10-18  1:04     ` Anh Vo
  2014-10-20 16:14     ` Adam Beneschan
  1 sibling, 0 replies; 18+ messages in thread
From: Anh Vo @ 2014-10-18  1:04 UTC (permalink / raw)


On Friday, October 17, 2014 5:04:17 PM UTC-7, Anh Vo wrote:
> On Friday, October 17, 2014 4:49:04 PM UTC-7, Adam Beneschan wrote:
> 
> > On Friday, October 17, 2014 4:22:15 PM UTC-7, Anh Vo wrote:
> > 
> > > What Ada spec should be for the following C prototype where BOOT_PARAMS is a struct and responding Ada type is
> 
> > > type Boot_Parameter_Type is
> > >    record
> > >       Boot_Dev : Interfaces.C.Strings.Chars_Ptr;
> > >       -- ...
> > >    end record;
> > > pragma Convention (C, Boot_Parameter_Type);
> > 
> > > type Boot_Parameter_Type_Access is access Boot_Parameter_Type;
> > > pragma Convention (C, Boot_Parameter_Type_Access);
> > 
> > > typedef struct           /* BOOT_PARAMS */
> > >     {
> > >     char bootDev [20];  /* boot device code */
> > >     * ... *
> > >     } BOOT_PARAMS;
> > 
> > > Note that I can not use Ada 2012 yet.
> > 
> > > char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams); 
> > 
> > I'm confused.  You've defined an Ada record Boot_Parameter_Type that has a pointer in it, and a C struct that does not have a pointer. 
> 
> > 
> The second parameter of the function prototype use pointer, BOOT_PARAMS * pBootParams.
> 

How this one.

function Boot_String_To_Type (
           Boot_String : Interfaces.C.Strings.chars_ptr;
           Boot_Params : System.Address) 
                             return Interfaces.C.Strings.chars_ptr;
pragma Import (C, Boot_String_To_Type, "bootStringToStruct");

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-17 23:22 Interface with C codes Anh Vo
  2014-10-17 23:30 ` Anh Vo
  2014-10-17 23:49 ` Adam Beneschan
@ 2014-10-18  2:20 ` Jeffrey Carter
  2014-10-18 17:00   ` Anh Vo
  2014-10-18  6:27 ` Per Sandberg
  3 siblings, 1 reply; 18+ messages in thread
From: Jeffrey Carter @ 2014-10-18  2:20 UTC (permalink / raw)


On 10/17/2014 04:22 PM, Anh Vo wrote:
> What Ada spec should be for the following C prototype where BOOT_PARAMS is a struct and responding Ada type is
> 
> type Boot_Parameter_Type is
>    record
>       Boot_Dev : Interfaces.C.Strings.Chars_Ptr;

This doesn't match the C quoted below. Use

                   Interfaces.C.Char_Array (0 .. 19);

>       -- ...
>    end record;
> pragma Convention (C, Boot_Parameter_Type);
> 
> type Boot_Parameter_Type_Access is access Boot_Parameter_Type;
> pragma Convention (C, Boot_Parameter_Type_Access);

You don't need this access type.

> char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams);

I would probably use

function To_Record
(Boot_String : Intefaces.C.Char_Array; Boot_Parameter : Boot_Parameter_Type)
return Interfaces.C.Strings.Chars_Ptr;

and rely on the advice in B.3(69-70): both parameters will be passed by reference.

-- 
Jeff Carter
"Whatever it is, I'm against it."
Horse Feathers
46


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-17 23:22 Interface with C codes Anh Vo
                   ` (2 preceding siblings ...)
  2014-10-18  2:20 ` Jeffrey Carter
@ 2014-10-18  6:27 ` Per Sandberg
  2014-10-18 17:08   ` Anh Vo
  3 siblings, 1 reply; 18+ messages in thread
From: Per Sandberg @ 2014-10-18  6:27 UTC (permalink / raw)


Ask the compiler
g++ -fdump-ada-spec ${header}
/Per

On 18.10.2014 01:22, Anh Vo wrote:
> What Ada spec should be for the following C prototype where BOOT_PARAMS is a struct and responding Ada type is
>
> type Boot_Parameter_Type is
>     record
>        Boot_Dev : Interfaces.C.Strings.Chars_Ptr;
>        -- ...
>     end record;
> pragma Convention (C, Boot_Parameter_Type);
>
> type Boot_Parameter_Type_Access is access Boot_Parameter_Type;
> pragma Convention (C, Boot_Parameter_Type_Access);
>
>
> typedef struct           /* BOOT_PARAMS */
>      {
>      char bootDev [20];  /* boot device code */
>      * ... *
>      } BOOT_PARAMS;
>
> Note that I can not use Ada 2012 yet.
>
>
> char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams);
>
>
> Anh Vo
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-18  2:20 ` Jeffrey Carter
@ 2014-10-18 17:00   ` Anh Vo
  0 siblings, 0 replies; 18+ messages in thread
From: Anh Vo @ 2014-10-18 17:00 UTC (permalink / raw)


On Friday, October 17, 2014 7:20:45 PM UTC-7, Jeffrey Carter wrote:
> On 10/17/2014 04:22 PM, Anh Vo wrote:
> 
> > What Ada spec should be for the following C prototype where BOOT_PARAMS is a struct and responding Ada type is 
> >  
> > type Boot_Parameter_Type is 
> >    record 
> >       Boot_Dev : Interfaces.C.Strings.Chars_Ptr; 
> This doesn't match the C quoted below. Use
>                    Interfaces.C.Char_Array (0 .. 19);

Thanks for that.
> 
> >       -- ...
> 
> >    end record;
> > pragma Convention (C, Boot_Parameter_Type); 
> >  
> > type Boot_Parameter_Type_Access is access Boot_Parameter_Type; 
> > pragma Convention (C, Boot_Parameter_Type_Access);
> 
> You don't need this access type.
> 
> > char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams);
> 
> I would probably use

> function To_Record 
> (Boot_String : Intefaces.C.Char_Array; Boot_Parameter : Boot_Parameter_Type) 
> return Interfaces.C.Strings.Chars_Ptr;

> and rely on the advice in B.3(69-70): both parameters will be passed by reference.

Thanks again. I have enough info to test it out. 

Anh Vo

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-18  6:27 ` Per Sandberg
@ 2014-10-18 17:08   ` Anh Vo
  2014-10-18 17:12     ` Simon Wright
  0 siblings, 1 reply; 18+ messages in thread
From: Anh Vo @ 2014-10-18 17:08 UTC (permalink / raw)


On Friday, October 17, 2014 11:27:24 PM UTC-7, Per Sandberg wrote:
> Ask the compiler 
> g++ -fdump-ada-spec ${header}

I did just exactly that. But, I had a problem because at least one of the included header in the included chain was not available.

I will create a stand alone header containing truct and function prototype only. Then, use g++ -fdump-ada-spec to generate the binding. 

Thank you all for your suggestions.

Anh Vo


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-18 17:08   ` Anh Vo
@ 2014-10-18 17:12     ` Simon Wright
  0 siblings, 0 replies; 18+ messages in thread
From: Simon Wright @ 2014-10-18 17:12 UTC (permalink / raw)


Anh Vo <anhvofrcaus@gmail.com> writes:

> On Friday, October 17, 2014 11:27:24 PM UTC-7, Per Sandberg wrote:
>> Ask the compiler 
>> g++ -fdump-ada-spec ${header}
>
> I did just exactly that. But, I had a problem because at least one of
> the included header in the included chain was not available.

Sometimes -fdump-ada-spec-slim will solve that for you.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-17 23:30 ` Anh Vo
@ 2014-10-18 18:33   ` Stephen Leake
  2014-10-19  4:33     ` Anh Vo
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Leake @ 2014-10-18 18:33 UTC (permalink / raw)


Anh Vo <anhvofrcaus@gmail.com> writes:

> On Friday, October 17, 2014 4:22:15 PM UTC-7, Anh Vo wrote:
>>  
>> char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams); 
>  
>> Anh Vo
>
> Should this one work?
>
> function Boot_String_To_Type (
>            Boot_String : Interfaces.C.Strings.chars_ptr;
>            Boot_Params : Boot_Parameter_Type_Access) 
>                              return Interfaces.C.Strings.chars_ptr;
> pragma Import (C, Boot_String_To_Type, "bootStringToStruct");

Looks good. but give -fdump-ada-spec a try.

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-18 18:33   ` Stephen Leake
@ 2014-10-19  4:33     ` Anh Vo
  2014-10-19  9:24       ` Simon Clubley
  2014-10-19 11:46       ` Brian Drummond
  0 siblings, 2 replies; 18+ messages in thread
From: Anh Vo @ 2014-10-19  4:33 UTC (permalink / raw)


On Saturday, October 18, 2014 11:33:32 AM UTC-7, Stephen Leake wrote:
> Anh Vo <anhvofrcaus@gmail.com> writes:
> > On Friday, October 17, 2014 4:22:15 PM UTC-7, Anh Vo wrote:
> >>  
> >> char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams); 
> >  
> > Should this one work?
> >
> > function Boot_String_To_Type (
> >            Boot_String : Interfaces.C.Strings.chars_ptr;
> >            Boot_Params : Boot_Parameter_Type_Access) 
> >                              return Interfaces.C.Strings.chars_ptr; 
> > pragma Import (C, Boot_String_To_Type, "bootStringToStruct");
> 
> Looks good. but give -fdump-ada-spec a try.

Yes, I tried and the result is below.

function bootStringToStruct (bootString : Interfaces.C.Strings.chars_ptr;
                                pBootParams : access BOOT_PARAMS)
                                   return Interfaces.C.Strings.chars_ptr;
pragma Import (CPP, bootStringToStruct,  "_Z18bootStringToStructPcP11BOOT_PARAMS");

Why was "_Z18bootStringToStructPcP11BOOT_PARAMS" generated for third parameter of pragma Import? I thought it should be "bootStringToStruct".

A. Vo
 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-19  4:33     ` Anh Vo
@ 2014-10-19  9:24       ` Simon Clubley
  2014-10-19 11:46       ` Brian Drummond
  1 sibling, 0 replies; 18+ messages in thread
From: Simon Clubley @ 2014-10-19  9:24 UTC (permalink / raw)


On 2014-10-19, Anh Vo <anhvofrcaus@gmail.com> wrote:
> On Saturday, October 18, 2014 11:33:32 AM UTC-7, Stephen Leake wrote:
>> Anh Vo <anhvofrcaus@gmail.com> writes:
>> > On Friday, October 17, 2014 4:22:15 PM UTC-7, Anh Vo wrote:
>> >>  
>> >> char *  bootStringToStruct (char * bootString,  BOOT_PARAMS * pBootParams); 
>> >  
>> > Should this one work?
>> >
>> > function Boot_String_To_Type (
>> >            Boot_String : Interfaces.C.Strings.chars_ptr;
>> >            Boot_Params : Boot_Parameter_Type_Access) 
>> >                              return Interfaces.C.Strings.chars_ptr; 
>> > pragma Import (C, Boot_String_To_Type, "bootStringToStruct");
>> 
>> Looks good. but give -fdump-ada-spec a try.
>
> Yes, I tried and the result is below.
>
> function bootStringToStruct (bootString : Interfaces.C.Strings.chars_ptr;
>                                 pBootParams : access BOOT_PARAMS)
>                                    return Interfaces.C.Strings.chars_ptr;
> pragma Import (CPP, bootStringToStruct,  "_Z18bootStringToStructPcP11BOOT_PARAMS");
>
> Why was "_Z18bootStringToStructPcP11BOOT_PARAMS" generated for third parameter of pragma Import? I thought it should be "bootStringToStruct".
>

It's known as a mangled symbol and is required with C++ (notice your
latter example is using "CPP" and not "C" on the pragma Import).

The "Name mangling in C++" section of the following might be useful:

http://en.wikipedia.org/wiki/Name_mangling

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-19  4:33     ` Anh Vo
  2014-10-19  9:24       ` Simon Clubley
@ 2014-10-19 11:46       ` Brian Drummond
  2014-10-19 13:58         ` Simon Wright
  1 sibling, 1 reply; 18+ messages in thread
From: Brian Drummond @ 2014-10-19 11:46 UTC (permalink / raw)


On Sat, 18 Oct 2014 21:33:03 -0700, Anh Vo wrote:

> On Saturday, October 18, 2014 11:33:32 AM UTC-7, Stephen Leake wrote:
>> Anh Vo <anhvofrcaus@gmail.com> writes:
>> > On Friday, October 17, 2014 4:22:15 PM UTC-7, Anh Vo wrote:
>> >>  
>> >> char *  bootStringToStruct (char * bootString,  BOOT_PARAMS *
>> >> pBootParams);
>> >  
>> > Should this one work?
>> >
>> > function Boot_String_To_Type (
>> >            Boot_String : Interfaces.C.Strings.chars_ptr;
>> >            Boot_Params : Boot_Parameter_Type_Access)
>> >                              return Interfaces.C.Strings.chars_ptr;
>> > pragma Import (C, Boot_String_To_Type, "bootStringToStruct");
>> 
>> Looks good. but give -fdump-ada-spec a try.
> 
> Yes, I tried and the result is below.
(C++ snipped)

Use gcc -fdump-ada-spec instead of g++ -fdump-ada-spec

- Brian

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-19 11:46       ` Brian Drummond
@ 2014-10-19 13:58         ` Simon Wright
  2014-10-19 17:33           ` Anh Vo
  0 siblings, 1 reply; 18+ messages in thread
From: Simon Wright @ 2014-10-19 13:58 UTC (permalink / raw)


Brian Drummond <brian3@shapes.demon.co.uk> writes:

> Use gcc -fdump-ada-spec instead of g++ -fdump-ada-spec

g++ does a better job, they say, but you need to use extern "C":

extern "C" {
   // C declarations go here
}

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-19 13:58         ` Simon Wright
@ 2014-10-19 17:33           ` Anh Vo
  0 siblings, 0 replies; 18+ messages in thread
From: Anh Vo @ 2014-10-19 17:33 UTC (permalink / raw)


On Sunday, October 19, 2014 6:58:18 AM UTC-7, Simon Wright wrote:
> Brian Drummond <brian3@shapes.demon.co.uk> writes:
> > Use gcc -fdump-ada-spec instead of g++ -fdump-ada-spec
> 
> g++ does a better job, they say, but you need to use extern "C":
> extern "C" { 
>    // C declarations go here 
> }

Both ways worked fine. Thank you all very much for the info.

A. Vo


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-18  0:04   ` Anh Vo
  2014-10-18  1:04     ` Anh Vo
@ 2014-10-20 16:14     ` Adam Beneschan
  2014-10-25  3:31       ` Anh Vo
  1 sibling, 1 reply; 18+ messages in thread
From: Adam Beneschan @ 2014-10-20 16:14 UTC (permalink / raw)


On Friday, October 17, 2014 5:04:17 PM UTC-7, Anh Vo wrote:

> > I'm confused.  You've defined an Ada record Boot_Parameter_Type that has a pointer in it, and a C struct that does not have a pointer. 

> The second parameter of the function prototype use pointer, BOOT_PARAMS * pBootParams.

My point was that if you have a record layout in Ada that has a pointer in it, and your record (struct) type definition in C doesn't have a pointer, there will be major problems.  The Ada program will pass a record that has (typically) 4 or 8 bytes of pointer data, but the C program will be expecting those bytes to be character data (and since it actually expects there to be 20 characters, it will be looking for character data past the end of the Ada record, possibly looking into other Ada variables or worse).  Jeff already addressed this by suggesting you change Boot_Dev's type to Char_Array.  

                                -- Adam

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Interface with C codes
  2014-10-20 16:14     ` Adam Beneschan
@ 2014-10-25  3:31       ` Anh Vo
  0 siblings, 0 replies; 18+ messages in thread
From: Anh Vo @ 2014-10-25  3:31 UTC (permalink / raw)


On Monday, October 20, 2014 9:14:25 AM UTC-7, Adam Beneschan wrote:
> On Friday, October 17, 2014 5:04:17 PM UTC-7, Anh Vo wrote:
> 
>>> I'm confused.  You've defined an Ada record Boot_Parameter_Type that has a pointer in it, and a C struct that does not have a pointer. 
> 
>> The second parameter of the function prototype use pointer, BOOT_PARAMS * pBootParams.
> 
> My point was that if you have a record layout in Ada that has a pointer in it, and your record (struct) type definition in C doesn't have a pointer, there will be major problems.  The Ada program will pass a record that has (typically) 4 or 8 bytes of pointer data, but the C program will be expecting those bytes to be character data (and since it actually expects there to be 20 characters, it will be looking for character data past the end of the Ada record, possibly looking into other Ada variables or worse).  Jeff already addressed this by suggesting you change Boot_Dev's type to Char_Array.  
> 

You are right. I ended up to use the g++ -fdump-ada-spec suggested by Per Sandberg and others. Yes, the Boot_Dev's is defined Char_Array type. The good news is that it worked good. Again, thank you all for your help.

Anh Vo

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-10-25  3:31 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-17 23:22 Interface with C codes Anh Vo
2014-10-17 23:30 ` Anh Vo
2014-10-18 18:33   ` Stephen Leake
2014-10-19  4:33     ` Anh Vo
2014-10-19  9:24       ` Simon Clubley
2014-10-19 11:46       ` Brian Drummond
2014-10-19 13:58         ` Simon Wright
2014-10-19 17:33           ` Anh Vo
2014-10-17 23:49 ` Adam Beneschan
2014-10-18  0:04   ` Anh Vo
2014-10-18  1:04     ` Anh Vo
2014-10-20 16:14     ` Adam Beneschan
2014-10-25  3:31       ` Anh Vo
2014-10-18  2:20 ` Jeffrey Carter
2014-10-18 17:00   ` Anh Vo
2014-10-18  6:27 ` Per Sandberg
2014-10-18 17:08   ` Anh Vo
2014-10-18 17:12     ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox