comp.lang.ada
 help / color / mirror / Atom feed
From: rieachus@comcast.net
Subject: Re: Too big
Date: Wed, 23 Mar 2016 16:25:16 -0700 (PDT)
Date: 2016-03-23T16:25:16-07:00	[thread overview]
Message-ID: <60331fea-1993-45eb-8459-b154c621a106@googlegroups.com> (raw)
In-Reply-To: <eb06b468-3a3c-4272-84d9-3a1dcc4a59df@googlegroups.com>

 
> What is the most likely reason? For example, the offending subunit contains a large number of "separate" procedures. Would it help to wrap them up in a package?
ther than heuristic methods
> 
> All sensible suggestions welcom

GNAT tends to insert separate units where they belong during compilation.  In other words, separate may be of use to you in organizing your program code, but the compiler never actually sees the unit as separate.

However, if you reuse separate unit names, when the compiler tries to merge the text, you can end up with an infinitely long source file.  Sounds like what is happening to you.

If you just cut and paste to remove separate units until it works, fine.  However, I suspect that you have a more subtle problem in that you are using separate units where you really should be using generics.  There is a sort of "Aha!" moment when you realize that generic instantiation in theory happens at execution time.  (In other words, the generic is instantiated--the formal generic parameters are replaced by the actual (generic) parameters, then the code is called as usual. Ada always goes through this two-step at execution time.  Most of the time one or the other--elaboration or calling--does most of the work, but they are always both done and in order.) The compiler may make several different code objects (at compile time) for a generic unit, and in some cases the correct unit will be selected during execution.

Sounds complex, but it really isn't.  A short example should help:

generic
  type Element is private;
  type My_Array is array (Integer) of Element;
function Reverse(MA: My_Array) is
  Temp: My_Array := MA;
  for I in 1..MA'length loop -- The array bounds here might be say, 11..19.
    Temp(MA'last-I+1) := MA(I);
  end loop;
  return Temp;
end Reverse;

When you say:  function Reverse_String is new Reverse(Character, String);
you get a regular function.  Junk: String := Reverse(Some_string);  Is then a normal call.

Why all this fancy stuff?  The two stages can be a natural separation of roles, and saves you from creating (sometimes) hundreds of busy little operations which you have to keep straight.  I suspect that this gives you the (source) readability you were trying to get with separate.

I think I got all that right.

  parent reply	other threads:[~2016-03-23 23:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 22:18 Too big mike-h
2016-03-23 22:23 ` Cotswold Mike
2016-03-23 23:04   ` Anh Vo
2016-03-24  7:51     ` Cotswold Mike
2016-03-23 23:05 ` Robert A Duff
2016-03-23 23:25 ` rieachus [this message]
2016-03-24  5:50 ` Niklas Holsti
replies disabled

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