* Export to a Namespace?
@ 2002-09-27 17:02 Jeremy T. Smith
2002-09-27 18:15 ` Pascal Obry
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jeremy T. Smith @ 2002-09-27 17:02 UTC (permalink / raw)
I'm supporting a large mass of legacy Ada and my boss wants to add new
functions using C++. There are about 2000 constants defined in the Ada
code that we'll need visible to C++. Not a problem, a quick Perl script
will add a pragma Export after each declaration. The values being
exported are resolved at compile time, otherwise I'd just duplicat the
declarations in C++.
BUT, our system architect is a stickler about not polluting the global
namespace, so can I export from Ada to a C++ namespace? Perhaps
something like (though this won't compile on my Green Hills compiler):
C++ Side:
namespace My_Wrapper {
extern int First_Val;
extern int Next_Val;
}
Ada Side:
First_Val : constant integer := Some_Withed_In_Named_Number;
pragma Export(CPP, First_Val, "My_Wrapper::First_Val");
Next_Val : constant integer := First_Val'Succ;
pragma Export(CPP, Next_Val, "My_Wrapper::Next_Val");
Any help would be much appreciated, even if it's just a "You can't do
that"!
Thanks
Jeremy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Export to a Namespace?
2002-09-27 17:02 Export to a Namespace? Jeremy T. Smith
@ 2002-09-27 18:15 ` Pascal Obry
2002-09-27 18:52 ` Stephen Leake
2002-10-02 15:35 ` Matthew Heaney
2 siblings, 0 replies; 4+ messages in thread
From: Pascal Obry @ 2002-09-27 18:15 UTC (permalink / raw)
"Jeremy T. Smith" <jeremy.t.smith2@boeing.com> writes:
> I'm supporting a large mass of legacy Ada and my boss wants to add new
> functions using C++.
This is the problem, do not fix the code, fix your boss :)
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Export to a Namespace?
2002-09-27 17:02 Export to a Namespace? Jeremy T. Smith
2002-09-27 18:15 ` Pascal Obry
@ 2002-09-27 18:52 ` Stephen Leake
2002-10-02 15:35 ` Matthew Heaney
2 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2002-09-27 18:52 UTC (permalink / raw)
"Jeremy T. Smith" <jeremy.t.smith2@boeing.com> writes:
> I'm supporting a large mass of legacy Ada and my boss wants to add new
> functions using C++. There are about 2000 constants defined in the Ada
> code that we'll need visible to C++. Not a problem, a quick Perl script
> will add a pragma Export after each declaration. The values being
> exported are resolved at compile time, otherwise I'd just duplicat the
> declarations in C++.
>
> BUT, our system architect is a stickler about not polluting the global
> namespace, so can I export from Ada to a C++ namespace? Perhaps
> something like (though this won't compile on my Green Hills compiler):
>
> C++ Side:
> namespace My_Wrapper {
> extern int First_Val;
> extern int Next_Val;
> }
>
> Ada Side:
> First_Val : constant integer := Some_Withed_In_Named_Number;
> pragma Export(CPP, First_Val, "My_Wrapper::First_Val");
> Next_Val : constant integer := First_Val'Succ;
> pragma Export(CPP, Next_Val, "My_Wrapper::Next_Val");
>
> Any help would be much appreciated, even if it's just a "You can't do
> that"!
Find out how the C++ compiler mangles the C++ name to the link name;
it may be something like My_Wrapper@Next_Val, but it's probably
worse. Then use the Link_Name parameter of Export to specify that link
name.
As Pascal said, it would be better to fix your boss!
--
-- Stephe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Export to a Namespace?
2002-09-27 17:02 Export to a Namespace? Jeremy T. Smith
2002-09-27 18:15 ` Pascal Obry
2002-09-27 18:52 ` Stephen Leake
@ 2002-10-02 15:35 ` Matthew Heaney
2 siblings, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 2002-10-02 15:35 UTC (permalink / raw)
"Jeremy T. Smith" <jeremy.t.smith2@boeing.com> wrote in message
news:3D948F1F.9A87CE48@boeing.com...
>
> BUT, our system architect is a stickler about not polluting the global
> namespace, so can I export from Ada to a C++ namespace? Perhaps
> something like (though this won't compile on my Green Hills compiler):
>
> C++ Side:
> namespace My_Wrapper {
> extern int First_Val;
> extern int Next_Val;
> }
The problem is you don't know how the compiler mangles names.
What I would do is use extern but with C linkage, e.g.
extern "C" {
extern int My_Wrapper_First_Val;
extern int My_Wrapper_Next_Val;
}
or something like that.
I'm not sure external linkage and C++ namespaces are really compatible.
If you really want to keep the namespace, you could try something like:
namespace My_Wrapper {
int First_Val();
int Next_Val();
}
inline int My_Wrapper::First_Val()
{
return My_Wrapper_First_Val;
}
inline int My_Wrapper::Next_Val()
{
return My_Wrapper_Next_Val;
}
or something like that.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-10-02 15:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-27 17:02 Export to a Namespace? Jeremy T. Smith
2002-09-27 18:15 ` Pascal Obry
2002-09-27 18:52 ` Stephen Leake
2002-10-02 15:35 ` Matthew Heaney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox