8 Replies - 262 Views - Last Post: 08 August 2018 - 03:33 PM Rate Topic: -----

#1 Woodsy   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 08-August 18

ADA -- The very beginning of my journey

Posted 08 August 2018 - 11:48 AM

Hi, complete and total noobie with ADA here. Just got my software (GPS 2018) installed and did my "Hello World" to make sure I know at least the most basic of basics.

Just a quickie question, when I opened my first project i chose to let GNAT open a Simple ADA Project, so I didn't have to do much, it had added in a null; that I have no idea what it's doing there unless it was just a placeholder?

with Ada.Text_IO;
use Ada.Text_IO;

procedure Main is

begin
   Put_Line("Hello World!");
   null;
end Main;



Anyway, if there are any ADA gurus out there I am sure to be pestering you through the coming weeks!

Is This A Good Question/Topic? 0
  • +

Replies To: ADA -- The very beginning of my journey

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14690
  • View blog
  • Posts: 58,701
  • Joined: 12-June 08

Re: ADA -- The very beginning of my journey

Posted 08 August 2018 - 11:53 AM

Is this a project you created inside GNAT, or just wrote up yourself in something like notepad?
Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11376
  • View blog
  • Posts: 19,408
  • Joined: 19-March 11

Re: ADA -- The very beginning of my journey

Posted 08 August 2018 - 11:54 AM

I suspect you're going to be our first ADA guru. Congatulations!
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14690
  • View blog
  • Posts: 58,701
  • Joined: 12-June 08

Re: ADA -- The very beginning of my journey

Posted 08 August 2018 - 11:54 AM

There may have just been an extra empty line it had to fill in with a null;.
Was This Post Helpful? 0
  • +
  • -

#5 Woodsy   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 08-August 18

Re: ADA -- The very beginning of my journey

Posted 08 August 2018 - 11:58 AM

Created in Gnat. File->New Project->Simple ADA Project. All I had to add was the with Ada.Text_IO; use Ada.Text_IO; and the Put_Line("Hello World!");.

View Postjon.kiparsky, on 08 August 2018 - 11:54 AM, said:

I suspect you're going to be our first ADA guru. Congatulations!

Actually did laugh out loud at that!
Was This Post Helpful? 1
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14690
  • View blog
  • Posts: 58,701
  • Joined: 12-June 08

Re: ADA -- The very beginning of my journey

Posted 08 August 2018 - 12:03 PM

Hmm.. my limited knowledge says the IDE was just dealing with an empty line.
Was This Post Helpful? 0
  • +
  • -

#7 Woodsy   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 08-August 18

Re: ADA -- The very beginning of my journey

Posted 08 August 2018 - 12:58 PM

So here's the first program past "Hello World".

with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
 
procedure main is

 procedure Double(Item : in out Integer) is
 begin -- procedure Double.
   Item := Item * 2;
 end Double;

 X : Integer := 1;

begin -- procedure main
 loop
  Put(X);
  New_Line;
  Double(X);
 end loop;
end main;



Differences, other than the obvious differences from other languages I have looked at, is the output of the program. When it runs it outputs: raised CONSTRAINT_ERROR : main.adb:9 overflow check failed when X is greater than 1073741824. So far I am digging it, but I will definitely pick up some books to read through.
Was This Post Helpful? 1
  • +
  • -

#8 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 11376
  • View blog
  • Posts: 19,408
  • Joined: 19-March 11

Re: ADA -- The very beginning of my journey

Posted 08 August 2018 - 01:30 PM

So your X = 1073741824 happens to be 2 ^ 30. My guess is that you've run into the maximum int value for your ADA implementation.
Was This Post Helpful? 0
  • +
  • -

#9 Woodsy   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 08-August 18

Re: ADA -- The very beginning of my journey

Posted 08 August 2018 - 03:33 PM

Quote

So your X = 1073741824 happens to be 2 ^ 30. My guess is that you've run into the maximum int value for your ADA implementation.


That's what it looks like.
This code -
with Ada.Text_IO;
use  Ada.Text_IO;
with Ada.Integer_Text_IO;
use  Ada.Integer_Text_IO;
            
procedure main is
   i: Integer := 882; -- initialized value for i
   x: Integer:= integer'Size; -- the size of an integer variable

begin
   put("The value of 'i' is");
   put(i);
   put(" but you can change that!");
   new_line;
   put("Enter an integer: ");  -- use a prompt
   get(i);  -- input a new value for int
   put("'i' is now:");
   put(i);  -- output the new value for int
   put(" and its size is:");
   put(x);  -- output the 'size of integer'
   new_line;
   
end main;


outputs:
C:\Projects\obj>main
The value of 'i' is          882 but you can change that!
Enter an integer: 9688213
'i' is now:    9688213 and its size is:         32


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1