comp.lang.ada
 help / color / mirror / Atom feed
* Re: ADA-C++ Elaboration
  2000-10-11  0:00 ADA-C++ Elaboration Pam Shimek
@ 2000-10-11  0:00 ` Ted Dennison
  2000-10-14  3:40 ` Robert Dewar
  1 sibling, 0 replies; 3+ messages in thread
From: Ted Dennison @ 2000-10-11  0:00 UTC (permalink / raw)


In article <39E4DBB5.BEE55D9C@csd.sgi.com>,
  Pam Shimek <pshimek@csd.sgi.com> wrote:

> code?  In particular, I am having problems with const C++ variables
> failing to initialize

Hmm. I wonder if its a problem with C++ having a runtime that needs to
be initialized. You would have trouble like that if you tried calling
Ada from another language. But Ada provides a routine with a standard
link name that you can call to initialize everything.

Try changing the const variables to #defines, and see if you get the
right value. If that works, you either need to figure out how to call
C++'s initialization code directly, or you need to find some compile
option that causes those variables to get loaded with the right value.

>    procedure SUB_C;
>    pragma import(C, SUB_C);
>    pragma interface_name(SUB_C, "sub_c");

"pragma interface_name" is a Gnat-specific pragma to allow backwards
compatability with some old DECAda code. Unless that is your situation,
you should be using
   pragma import (C, SUB_C, "sub_c");
instead. Changing it won't fix your current problem though.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html
Day 6 of Free Europe


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* ADA-C++ Elaboration
@ 2000-10-11  0:00 Pam Shimek
  2000-10-11  0:00 ` Ted Dennison
  2000-10-14  3:40 ` Robert Dewar
  0 siblings, 2 replies; 3+ messages in thread
From: Pam Shimek @ 2000-10-11  0:00 UTC (permalink / raw)


Hi,

I have an ADA call to a C++ subroutine, which appears to fail at
elaboration time.
Are there some special linkage flags that gnatmake/gnatlink need to
indicate where the
C++ linker is?  Or is there some interface/pragma that needs to be
specified in the ADA
code?  In particular, I am having problems with const C++ variables
failing to initialize
during elaboration time:



ADA code:

***********************************

with text_io;

procedure main_ada is

   procedure SUB_C;
   pragma import(C, SUB_C);
   pragma interface_name(SUB_C, "sub_c");


begin


   SUB_C;

end main_ada;


*******************************

C++ code:

**************************

#include <iostream.h>

const   float a = 100.0;
const   float b = 3.0;
const   float c = ( a / b );

extern "C"
void sub_c( void )
   {
   float d = a / b;

   cout << "   sub_c" << endl;
   cout << "      a = " << a << endl;
   cout << "      b = " << b << endl;
   cout << "      c = " << c << endl;
   cout << "      d = " << d << endl;
   }


**********************************


The value of the variable "c" reports back 0.


Compiled as:

CC -n32 -c -g *.cc
CC -n32 -g -o main_c main_c.o sub_c.o


if (! -e adalib) then
   mkdir adalib
endif
cd adalib
gnatmake -n32 -k -c -g -j1 -O2 ../main_ada.adb
gnatbind -n32 -v          -x main_ada.ali
gnatlink -n32 -o ../main_ada -g main_ada.ali \
        -L/usr/lib32 \
        -L/usr/gnu/lib/gcc-lib/mips-sgi-irix6-n32/2.8.1 \
        ../sub_f.o ../sub_c.o \
        -lftn -lftn90 -lfortran \
        -lm -lCsup -lC -lSgw 

Tried adding  --GNATLINK=c++ to the gnatlink line, to no
avail.


Thanks!

Pam




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

* Re: ADA-C++ Elaboration
  2000-10-11  0:00 ADA-C++ Elaboration Pam Shimek
  2000-10-11  0:00 ` Ted Dennison
@ 2000-10-14  3:40 ` Robert Dewar
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 2000-10-14  3:40 UTC (permalink / raw)


In article <39E4DBB5.BEE55D9C@csd.sgi.com>,
  Pam Shimek <pshimek@csd.sgi.com> wrote:
> Hi,
>
> I have an ADA call to a C++ subroutine, which appears to fail
> at elaboration time.

I will once again disclose the existence of the secret archives
used by the wizards to answer such deep magical questions. These
archives are referred to by the arcane general term of GNAT
documentation, and have incomprehensible titles like "GNAT
User's Guide".

Even when you manage to locate this secret tome, it is hard
to find what you want, because all items are hidden in sections
with titles designed to make it impossible to find what you
are looking for.

For example, in this particular case, who could guess that
a useful chapter to read would have the obscure title:

  Building mixed Ada & C++ programs

:-)

Seriously, you will find useful information there ...





Sent via Deja.com http://www.deja.com/
Before you buy.



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

end of thread, other threads:[~2000-10-14  3:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-11  0:00 ADA-C++ Elaboration Pam Shimek
2000-10-11  0:00 ` Ted Dennison
2000-10-14  3:40 ` Robert Dewar

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