I would like to declare some “user-defined compiler-constants” to keep my specification files as “constant” as possible. This is something common in C++, e.g. :
// misc/config.hh
namespace misc
{
typedef std::shared_ptr<A> A_ptr;
namespace arch = ibmpc;
}
// misc/code.hh
#include "misc/config.hh"
namespace misc
{
void function p(A_ptr a);
}
Which would be in Ada :
-- misc.ads
package Misc is
use Types; ----> forbidden !
procedure P(A : A_Access);
end Misc;
-- misc-types.ads
package Misc.Types is
type A_Access is A'Access;
end Misc.Types;
Of course this does not work since use is a context keyword…hence my question : how is it possible to do something with the same results in Ada ?
I think this is a reasonable mapping from your C++ original to Ada:
To start with, corresponding more-or-less, I think, to your
namespace misc, in filemisc.ads,Then, corresponding to
config.hh, in filemisc-config.ads,(which could, of course, also reference types in
Misc). Then, corresponding tocode.hh, in filemisc-code.ads,Personally I wouldn’t
use Config;, at any rate in specs – it can make it difficult to work out where something is defined. Note, you can sayuse Config;oruse Misc.Config;where shown, because you’re in a child ofMisc; in the context clause, which is also OK, you would have touse Misc.Config;.