From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3d9e8b4af1a21f1e X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!d21g2000prf.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: newline in a simple program Date: Tue, 18 Dec 2007 08:44:57 -0800 (PST) Organization: http://groups.google.com Message-ID: <86edc763-de4c-4c41-a530-ddd43874e559@d21g2000prf.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1197996297 28682 127.0.0.1 (18 Dec 2007 16:44:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 18 Dec 2007 16:44:57 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d21g2000prf.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:18989 Date: 2007-12-18T08:44:57-08:00 List-Id: On Dec 18, 4:28 am, Paul wrote: > Hi, given the following two simple programs > > hello.adb > ----------------------- > with ada.text_io; > procedure hello is > begin > ada.text_io.put("hello"); > end hello; > ----------------------- > > hello.c > ----------------------- > #include > int main() > { > printf("hello");} > > ----------------------- > > the result for the ada program is: > ----------------------- > $ ./hello_in_ada > hello > $ > ----------------------- > > and for the c program: > ----------------------- > $ ./hello_in_c > hello$ > ----------------------- > > The c program does not print a new-line, but the ada program does. > > Is there any way to make the ada program not print a new-line? > > And is this behavior part of the Ada standard or is it just part of gnat? Regarding whether this is part of the Ada standard or not: this actually is not a simple yes/no question. The Ada standard says that when an output file is closed, the effect of New_Page takes place (A. 10.2(3)); this means that a "line terminator" is written if the current line is not already terminated, and that a "page terminator" is written if the current page is not already terminated. However, "line terminator" and "page terminator" are logical concepts, and the standard makes clear that they don't have to be represented by actual characters in a file. (If, for example, an *input* text file on a Unix-type system does not end in a newline, I believe a reasonable Ada implementation would treat the logical end-of-file as a line terminator, as well as a page terminator, even though there are no bytes in the file to indicate the end of line.) What this does mean, though, is that logically, it doesn't matter whether the last output operation to the file is New_Line/Put_Line or not. Thus, in some sense, these have the same effect: ... Text_IO.Put_Line (File, "ABC"); Text_IO.Put (File, "DEF"); Text_IO.Close (File); and ... Text_IO.Put_Line (File, "ABC"); Text_IO.Put_Line (File, "DEF"); Text_IO.Close (File); since in the second case, the last Put_Line will output a line terminator; and in the first case, the Close will output a line terminator because the current line hasn't yet been terminated. So it doesn't surprise me that it's hard to use Text_IO to write a text file that isn't terminated by newline. If you really want this, you have to go "outside Ada" to tell the implementation something about the actual bytes you want put into the file (Ada doesn't define this). Some Ada implementations may provide this ability in the Form parameter when you open the file. Hope this helps, -- Adam