comp.lang.ada
 help / color / mirror / Atom feed
* Ada equivalent of C "static" structures
@ 1997-03-07  0:00 Michael Ibarra
  1997-03-07  0:00 ` john schneider
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Michael Ibarra @ 1997-03-07  0:00 UTC (permalink / raw)



I'm wondering if anyone can point me in the right direction:

I need to declare a record which has "file" scope.  This would be
something that every unit within this file could access, but could
not be accessed from any unit outside of this file.

Any ideas???

thanks in advance
-Mike




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

* Re: Ada equivalent of C "static" structures
  1997-03-07  0:00 Ada equivalent of C "static" structures Michael Ibarra
@ 1997-03-07  0:00 ` john schneider
  1997-03-07  0:00 ` Robert Dewar
  1997-03-08  0:00 ` John McCabe
  2 siblings, 0 replies; 6+ messages in thread
From: john schneider @ 1997-03-07  0:00 UTC (permalink / raw)



Michael Ibarra wrote:
> 
> I'm wondering if anyone can point me in the right direction:
> 
> I need to declare a record which has "file" scope.  This would be
> something that every unit within this file could access, but could
> not be accessed from any unit outside of this file.
> 
> Any ideas???
> 
> thanks in advance
> -Mike

Define your record in the package BODY rather than in the spec.
Only other units declared in the package will be able to access it.

John Schneider
j-schneider@ti.com

The opinions are mine, but you are welcome to borrow them.




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

* Re: Ada equivalent of C "static" structures
  1997-03-07  0:00 Ada equivalent of C "static" structures Michael Ibarra
  1997-03-07  0:00 ` john schneider
@ 1997-03-07  0:00 ` Robert Dewar
  1997-03-08  0:00 ` John McCabe
  2 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1997-03-07  0:00 UTC (permalink / raw)



Mike, you asked

<<I need to declare a record which has "file" scope.  This would be
something that every unit within this file could access, but could
not be accessed from any unit outside of this file.

Any ideas???

thanks in advance>>

Sounds like you need to do some basic reading in Ada structuring and
visibility, since this is an extremely elementary question. The important
thing is not just to get an answer to your question (which is simple, 
just define a variable at the level of the package body), but rather
to understand the general mechanisms, since Ada is MUCH mor powerful
than C in this area, so you want to go much beyond just duplicating
C faclities.

You might find one of the online tutorials worthwhile, checkout
www.adahome.com.





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

* Re: Ada equivalent of C "static" structures
  1997-03-07  0:00 Ada equivalent of C "static" structures Michael Ibarra
  1997-03-07  0:00 ` john schneider
  1997-03-07  0:00 ` Robert Dewar
@ 1997-03-08  0:00 ` John McCabe
  1997-03-08  0:00   ` Robert Dewar
  2 siblings, 1 reply; 6+ messages in thread
From: John McCabe @ 1997-03-08  0:00 UTC (permalink / raw)



Michael Ibarra <ibarra@mccabe.com> wrote:

>I'm wondering if anyone can point me in the right direction:
>
>I need to declare a record which has "file" scope.  This would be
>something that every unit within this file could access, but could
>not be accessed from any unit outside of this file.
>
>Any ideas???
>
>thanks in advance
>-Mike

This really depends on exactly what you require. If you have 1 package
to each file then Mr. Schneider's answer should be adequate, however
if you are intending to have more than 1 package in a file then you
will need to look closer at the overall structure. I'm sure I'll be
corrected if I'm wrong here, but Ada doesn't support e.g.

with System;

type X is record
	:
	:
end record;

package body p_1 is
	:
	:
end p_1;

package body p_2 is
	:
	:
end p_2;

All type and object definitions must be within a program unit, and a
file isn't one of those. You cold put a package definition round the
above stuff, but then (In Ada 83) you would run into complications.

My advice would be to define a separate package with the type or
object definition you require, and only "with" it in a single file
e.g:

*file1*
package data_package is
	type x is record
		:
		:
	end record;

	x_value : x;
end data_package;

*file2*
with data_package;
package body p_1 is
	:
	:
end p_1;

package body p_2 is
	:
	:
end p_2;

etc.


Best Regards
John McCabe <john@assen.demon.co.uk>




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

* Re: Ada equivalent of C "static" structures
  1997-03-08  0:00 ` John McCabe
@ 1997-03-08  0:00   ` Robert Dewar
  1997-03-09  0:00     ` John McCabe
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Dewar @ 1997-03-08  0:00 UTC (permalink / raw)



John suggests

<<My advice would be to define a separate package with the type or
object definition you require, and only "with" it in a single file
e.g:

*file1*
package data_package is
        type x is record
                :
                :
        end record;

        x_value : x;
end data_package;

*file2*
with data_package;
package body p_1 is
        :
        :
end p_1;

>>

Robert replies

If data_package is only going to be with'ed from p_1, then make it a
private child of p_1, but far simpler, as suggested by several replies,
already, is just to define x_value within the body of p_1. I am not
sure why John is suggesting a separate package here, it seems entirely
unnecessary.





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

* Re: Ada equivalent of C "static" structures
  1997-03-08  0:00   ` Robert Dewar
@ 1997-03-09  0:00     ` John McCabe
  0 siblings, 0 replies; 6+ messages in thread
From: John McCabe @ 1997-03-09  0:00 UTC (permalink / raw)



dewar@merv.cs.nyu.edu (Robert Dewar) wrote:

>John suggests
>
><<My advice would be to define a separate package with the type or
>object definition you require, and only "with" it in a single file
>e.g:
>
>*file1*
>package data_package is
>        type x is record
>                :
>                :
>        end record;
>
>        x_value : x;
>end data_package;
>
>*file2*
>with data_package;
>package body p_1 is
>        :
>        :
>end p_1;
>
>>>
>
>Robert replies
>
>If data_package is only going to be with'ed from p_1, then make it a
>private child of p_1, but far simpler, as suggested by several replies,
>already, is just to define x_value within the body of p_1. I am not
>sure why John is suggesting a separate package here, it seems entirely
>unnecessary.
>

You're quite right. I missed out the "with" for p_2 i.e.:

*file2*
with data_package;
package body p_1 is
	:
	:
end p_1;

with data_package;  -- Originally missed this out!
package body p_2 is
	:
	:
end p_2;


Best Regards
John McCabe <john@assen.demon.co.uk>




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

end of thread, other threads:[~1997-03-09  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-07  0:00 Ada equivalent of C "static" structures Michael Ibarra
1997-03-07  0:00 ` john schneider
1997-03-07  0:00 ` Robert Dewar
1997-03-08  0:00 ` John McCabe
1997-03-08  0:00   ` Robert Dewar
1997-03-09  0:00     ` John McCabe

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