comp.lang.ada
 help / color / mirror / Atom feed
* Uninitialized variable and the effects they have
@ 2005-11-24  9:36 Maciej Sobczak
  2005-11-24 11:49 ` Martin Dowie
  2005-11-24 16:33 ` Wilhelm Spickermann
  0 siblings, 2 replies; 3+ messages in thread
From: Maciej Sobczak @ 2005-11-24  9:36 UTC (permalink / raw)


Hello,

Consider:

procedure Hello is
    I : Integer;  -- uninitialized
begin
    case I is
       when 5 => Put("I got five!");
       when others => Put("I got something else");
    end case;

    -- continue with further statements
    -- ...

end Hello;

Is the behaviour of this program well-defined?
I mean - I consider it to be well defined if it's guaranteed that 
exactly one of the branches is chosen and later statements are executed 
without any restrictions.

What bothers me is the fact that AARM seems to guarantee this 
(5.4/10.b), but at the same time this would mean that the implementation 
may need to take some special steps to make it happen. On the platform 
where the integer type is allowed to have trap values in its 
representation (ie. there are possible bit patterns that are not 
considered to be valid numbers, which may cause the CPU to trigger bus 
error events or alike), the Ada implementation would need to somehow 
take care of them and route them to the "others" category. On the other 
hand, catching CPU critical errors might not be possible at all, or 
might in fact hide true hardware errors. Granted, the implementation is 
not obliged to use the underlying hardware in the straightforward way. 
What is really intended here?

This can be also restated another way:

I : Integer; -- uninitialized
J : Integer := I + 2;

What can be said about this code, with similar issues in mind?

Note that in C++ using (let's say reading) the uninitialized variable 
causes undefined behaviour, so both examples above could cause whatever 
effect on more exotic platform (including hardware lockup - why not?). 
If Ada makes it well-defined, I would like to know how it does it.
Please do not hesitate to point me to relevant AARM chapters.

Regards,

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



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

end of thread, other threads:[~2005-11-24 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-24  9:36 Uninitialized variable and the effects they have Maciej Sobczak
2005-11-24 11:49 ` Martin Dowie
2005-11-24 16:33 ` Wilhelm Spickermann

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