Talk:Day of the week: Difference between revisions

Content added Content deleted
(→‎Ada program: ada hard time)
(→‎Ada hard time...: It is clear now)
Line 88: Line 88:


Anyway, at least I ''discovered'' how to ''arrange'' the code on my system with my poor GNAT :) --[[User:ShinTakezou|ShinTakezou]] 20:52, 12 December 2008 (UTC)
Anyway, at least I ''discovered'' how to ''arrange'' the code on my system with my poor GNAT :) --[[User:ShinTakezou|ShinTakezou]] 20:52, 12 December 2008 (UTC)

: I see, now it seems to be clear. First of all, GNAT.Calendar is not a part of the standard. But that is not the problem, Ada.Calendar is. The standard ([[Ada 2005]]) requires Year_Number to be at least in the range 1901..2399. See [http://www.adaic.org/standards/1zrm/html/RM-9-6.html LRM 9.6 11/2]. So the code given in the Ada solution '''must''' work, or else your compiler is not Ada 2005. From your attempts I deduce that it is indeed not. You have an [[Ada 95]] compiler. In Ada 95 the range of Number was narrower, 1901 .. 2099. This is why your code produces an exception. You can slightly modify your code:
<blockquote>
<ada>
with GNAT.Calendar; use GNAT.Calendar;
with GNAT.Calendar.Time_IO; use GNAT.Calendar.Time_IO;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;

procedure Yuletide is
begin
for Year in Year_Number range 2008..2121 loop -- Explicitly specify it as Year_Number
if Day_Of_Week (Time_Of (Year, 12, 25, 0, 0, 0)) = Sunday then
Put_Line (Image (Time_Of (Year, 12, 25, 0,0,0), ISO_Date));
end if;
end loop;
end Yuletide;</ada>
</blockquote>
:Now the compiler will warn you that Year is not in the range of Year_Number and you will get Constraint_Error at run time. So the problem is that your GNAT is not [[Ada 2005]]. Remove it and install a new one. The official distributor is [https://libre.adacore.com here]. Register yourself (it is free) and download GNAT GPL for your platform. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 21:48, 12 December 2008 (UTC)


==When failing and when not on 32bit machine==
==When failing and when not on 32bit machine==