comp.lang.ada
 help / color / mirror / Atom feed
* Imported deferred constant with an address clause legal?
@ 1999-02-18  0:00 Rod Chapman
  1999-02-19  0:00 ` Steve Quinlan
  1999-03-01  0:00 ` Robert A Duff
  0 siblings, 2 replies; 6+ messages in thread
From: Rod Chapman @ 1999-02-18  0:00 UTC (permalink / raw)


A quick question for the language lawyers...

I have an embedded application which as a big EEPROM with lots of data
tables on it.  I want to map an Ada object to a location in the EEPROM.
Normally, I could do:

  with System.Storage_Elements;
  package My_EEPROM is
     Obj : Integer;
     for Obj'Address use System.Storage_Elements.To_Address(...);
  end My_EEPROM;

which works just fine.  BUT, what if I want to tell the compiler
(and our dataflow analyser) that this really _is_ a constant object
(it's in an EEPROM after all...)?  How about using Ada95's
trick of allowing a deferred constant to be completed by pragma
Import...

  with System.Storage_Elements;
  package My_EEPROM is
     Obj : constant Integer;
     pragma Import(Assembler, Obj);  -- Assembler? Seems OK...
     for Obj'Address use System.Storage_Elements.To_Address(...);
  end My_EEPROM;

Is that idiom legal?  Portable?  Implementaion dependent?  I can't
decide if it's reasonable to expect such a trick to work or not...

Thanks in advance,
 Rod Chapman
 Praxis Critical Systems.




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

* Re: Imported deferred constant with an address clause legal?
  1999-02-18  0:00 Imported deferred constant with an address clause legal? Rod Chapman
@ 1999-02-19  0:00 ` Steve Quinlan
  1999-02-20  0:00   ` robert_dewar
  1999-03-01  0:00 ` Robert A Duff
  1 sibling, 1 reply; 6+ messages in thread
From: Steve Quinlan @ 1999-02-19  0:00 UTC (permalink / raw)


I'm not a language lawyer, more like a language paralegal, but I don't
think this will work. If you use Pragma Import, an object of that name will
be expected to get resolved at link time. I think it is even illegal to
have an address clause for an imported object, because the address is
supposed to be determined at link time when the object is resolved.

Your first method seems more appropriate when you want to force a
representation at a particular memory location, vs. trying to get access to
a foreight data object which has been defined in some external object
module.






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

* Re: Imported deferred constant with an address clause legal?
  1999-02-19  0:00 ` Steve Quinlan
@ 1999-02-20  0:00   ` robert_dewar
  1999-02-20  0:00     ` Steve Quinlan
  0 siblings, 1 reply; 6+ messages in thread
From: robert_dewar @ 1999-02-20  0:00 UTC (permalink / raw)


In article <36CDFBB2.853482C@lmco.com>,
  Steve Quinlan <steven.quinlan@lmco.com> wrote:

> I'm not a language lawyer, more like a language
> paralegal, but I don't think this will work. If you use
> Pragma Import, an object of that name will
> be expected to get resolved at link time. I think it is
> even illegal to have an address clause for an imported
> object, because the address is supposed to be determined
> at link time when the object is resolved.

Not only is it legal to have an address clause for an
imported object, but it is a standard diction, mentioned
in the reference manual. A lot of people don't know this
particular rule, and it is one of the cases where GNAT
considers it a good idea to give a warning with the
appropriate RM reference :-) :-)

 1. procedure c is
 2.    type r is record
 3.       x : integer := 0;
 4.    end record;
 5.    b : integer;
 6.    c : r;
 7.    for c'address use b'address;
           |
 >>> warning: implicit initialization of "c" may modify "b"
 >>> warning: use pragma Import for "c" to suppress
              initialization (RM B(24))

 8.
 9. begin
10.    null;
11. end;

The RM also suggests the use of pragma Import and an
address clause together to achieve the effect of an
indirect subprogram call (and there is even an ACVC
test to see if you do this right!) This was a common
Ada 83 diction.

The expectation is that if you have a pragma Import and
an address clause, then the address clause overrides the
linker, and the linker is NOT used to resolve the address
in this case.

Robert Dewar
Ada Core Technologies

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Imported deferred constant with an address clause legal?
  1999-02-20  0:00   ` robert_dewar
@ 1999-02-20  0:00     ` Steve Quinlan
  1999-02-21  0:00       ` robert_dewar
  0 siblings, 1 reply; 6+ messages in thread
From: Steve Quinlan @ 1999-02-20  0:00 UTC (permalink / raw)


Blew that one -- back to language law school.

"How do I know? -- my compiler tells me so"






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

* Re: Imported deferred constant with an address clause legal?
  1999-02-20  0:00     ` Steve Quinlan
@ 1999-02-21  0:00       ` robert_dewar
  0 siblings, 0 replies; 6+ messages in thread
From: robert_dewar @ 1999-02-21  0:00 UTC (permalink / raw)


In article <36CEF0AF.AEEA888D@lmco.com>,
  Steve Quinlan <steven.quinlan@lmco.com> wrote:
> Blew that one -- back to language law school.

No No, please don't go there. The Ada world is like
the real world, we have too many lawyers already,
better to concentrate on actually building useful
stuff with Ada!

(and that is indeed what Steve really does :-)

Robert

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Imported deferred constant with an address clause legal?
  1999-02-18  0:00 Imported deferred constant with an address clause legal? Rod Chapman
  1999-02-19  0:00 ` Steve Quinlan
@ 1999-03-01  0:00 ` Robert A Duff
  1 sibling, 0 replies; 6+ messages in thread
From: Robert A Duff @ 1999-03-01  0:00 UTC (permalink / raw)


Rod Chapman <rod@praxis-cs.co.uk> writes:

>   package My_EEPROM is
>      Obj : constant Integer;
>      pragma Import(Assembler, Obj);  -- Assembler? Seems OK...
>      for Obj'Address use System.Storage_Elements.To_Address(...);
>   end My_EEPROM;

That's fine, except you probably want convention Ada rather than
Assembler.  "Ada" means you have arranged for that memory location in
the EEPROM to be represented like the Ada compiler wants.

It's often a good idea to give a pragma Import for a address-claused
thing, because that turns off implicit initialization -- see
AARM-B.1(38,38.a).  If the Ada compiler generates code to implicitly
initialize a ROM, you're in trouble.  Your example uses Integer, so it
doesn't matter, but if it had been an access type, you need the pragma
to turn off null-ing it.

See also AARM-C.6(13, 13.b).  If you say "constant" as above, and some
external code modifies it, you're in trouble unless you also say "pragma
Volatile".

- Bob
-- 
Change robert to bob to get my real email address.  Sorry.




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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-18  0:00 Imported deferred constant with an address clause legal? Rod Chapman
1999-02-19  0:00 ` Steve Quinlan
1999-02-20  0:00   ` robert_dewar
1999-02-20  0:00     ` Steve Quinlan
1999-02-21  0:00       ` robert_dewar
1999-03-01  0:00 ` Robert A Duff

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