comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: How to Emulate C++ Macro with Static Local Variable?
Date: Sun, 28 Sep 2003 20:06:25 GMT
Date: 2003-09-28T20:06:25+00:00	[thread overview]
Message-ID: <5bHdb.6832$RW4.2763@newsread4.news.pas.earthlink.net> (raw)
In-Reply-To: <3F769EDE.D9D4744F@fakeaddress.nil>

Gautier Write-only wrote:

> package BARs is
> 
>   type S is array(0..7) of Integer;
> 
>   generic
>     foo: Integer;
>   package P is
>     procedure BAR;
>   end;
>   
> end;
> 
> with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO;
> 
> package body BARs is
> 
>   package body P is
>     initialized: Boolean:= False;
>     cache: S;
>     procedure BAR is
>     begin
>       if not initialized then
>         cache:= (others=> foo);
>         New_Line;
>         Put_Line("[Filling cache for instance]" & Integer'image(foo));
>         initialized:= True;
>       end if;
>       Put(cache(cache'last));
>     end;
>   end;
> 
> end BARs;

There seems to be no need for type S. Why not have

generic
    Foo : Integer;
package BARs is
    procedure BAR;
end BARs;

with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
package body BARs is
    Cache : Integer := Foo;

    procedure BAR is
    begin
        Put (Cache);
    end BAR;
end BARs;

-- 
Jeff Carter
"Oh Lord, bless this thy hand grenade, that with it thou
mayst blow thine enemies to tiny bits, in thy mercy."
Monty Python and the Holy Grail
24




  reply	other threads:[~2003-09-28 20:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-24 22:06 How to Emulate C++ Macro with Static Local Variable? taashlo
2003-09-24 23:44 ` Robert I. Eachus
2003-09-25  3:27   ` Hyman Rosen
2003-09-25  4:53     ` tmoran
2003-09-25 15:57       ` Robert I. Eachus
2003-09-25 19:09         ` tmoran
2003-09-29 14:57           ` taashlo
2003-09-29 18:12             ` Jeffrey Carter
2003-09-29 18:51               ` taashlo
2003-09-30  1:32                 ` Jeffrey Carter
2003-09-30  1:54                   ` tmoran
2003-09-30 13:02                   ` taashlo
2003-09-30 20:25                     ` Jeffrey Carter
2003-09-30  2:45             ` Robert I. Eachus
2003-09-30  3:24               ` tmoran
2003-09-25 13:43     ` Stephen Leake
2003-09-25 12:59   ` Tad Ashlock
2003-09-25 16:11     ` Robert I. Eachus
2003-09-25 18:13       ` Randy Brukardt
2003-09-25 23:40         ` Robert I. Eachus
2003-09-25 11:54 ` Gautier
2003-09-25 16:14   ` Robert I. Eachus
2003-09-25 18:06   ` Tad Ashlock
2003-09-28  8:42     ` Gautier Write-only
2003-09-28 20:06       ` Jeffrey Carter [this message]
2003-09-29  2:13         ` Gautier Write-only
2003-09-25 13:41 ` Stephen Leake
2003-09-25 17:23   ` Tad Ashlock
replies disabled

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