comp.lang.ada
 help / color / mirror / Atom feed
From: Hyman Rosen <hyrosen@mail.com>
Subject: Re: Real data for a change in the assignment operators and Bounded_String discussions.
Date: Mon, 07 Jul 2003 04:27:55 GMT
Date: 2003-07-07T04:27:55+00:00	[thread overview]
Message-ID: <fF6Oa.14365$Ha.10004@nwrdny02.gnilink.net> (raw)
In-Reply-To: <3F04F778.5090305@attbi.com>

Robert I. Eachus wrote:
>     Open(Input_File,In_File,Argument(1));
>     return Recur;
>     Close(Input_File);

What's this? Does Ada come with a delay slot?

 > You just CANNOT code like this in C or many other languages.

True.

> (I can imagine trying to write that code in C, with  mallocs, frees,
 > searches for nul (strlen) and copies all over the place. Ouch!)

Well, let's see (error checking left out):
     char *first_line_of_file(char *file_name)
     {
         int nread = 0, capacity = 0, c;
         char *buf = 0;
         FILE *f = fopen(file_name, "r");
	while ((c = fgetc(f)) != EOF && c != '\n')
         {
             if (nread >= capacity)
                  buf = realloc(buf, capacity += 80);
             buf[nread++] = c;
         }
         fclose(f);
         if (nread >= capacity)
             buf = realloc(buf, capacity + 1);
         buf[nread] = 0;
         return realloc(buf, nread + 1);
     }

I suggest your imagination was unequal to the task. And in C++,
the whole thing is a single call to std::getline.

> I don't expect this to end the discussion on these two issues, but I 
> hope it helps.  The three calls in a row to Inc are much clearer than:

But you have cheated, by having all three lines increment an Integer.
Ada not being C, there are a proliferation of user-defined types that
all need incrementing, so soon the code is crawling with simple little
Inc and Dec procedures. The idea behind having special assignment
operators (or idem) is precisely to avod having to write these little
procedures for every such type.




  parent reply	other threads:[~2003-07-07  4:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-04  3:41 Real data for a change in the assignment operators and Bounded_String discussions Robert I. Eachus
2003-07-05  1:29 ` Inc (was: Real data for a change in the assignment operators and Bounded_String discussions. ) Alexander Kopilovitch
2003-07-07 21:31   ` Gautier Write-only
2003-07-07 21:35     ` Inc (was: Real data for a change in the assignment operators and Larry Kilgallen
2003-07-08  3:53       ` Gautier Write-only
2003-07-08 20:50       ` Alexander Kopilovitch
2003-07-07 21:42     ` Inc (was: Real data for a change in the assignment operators and Bounded_String discussions. ) Vinzent Hoefler
2003-07-08  4:04       ` Gautier Write-only
2003-07-07  4:27 ` Hyman Rosen [this message]
2003-07-07  9:27   ` Real data for a change in the assignment operators and Bounded_String discussions Georg Bauhaus
2003-07-07  9:41     ` Georg Bauhaus
2003-07-07 14:29       ` Hyman Rosen
2003-07-07 17:29         ` Georg Bauhaus
2003-07-07 19:01           ` Hyman Rosen
2003-07-07 15:49       ` Robert I. Eachus
2003-07-07 13:46     ` Hyman Rosen
2003-07-07 16:03       ` Robert I. Eachus
2003-07-07 18:52         ` Hyman Rosen
replies disabled

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