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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: GNAT.Serial_Communication and Streams Date: Tue, 24 Nov 2015 09:28:55 +0100 Organization: cbb software GmbH Message-ID: References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: uuaYi8S0HktMvp6/JW1g+A.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:28516 Date: 2015-11-24T09:28:55+01:00 List-Id: On Sun, 22 Nov 2015 14:54:04 -0700, Jeffrey R. Carter wrote: > What about > > procedure Send (Cmd : in String) is > Local : constant String := Cmd & Ada.Characters.Latin_1.LF; > Output : constant Ada.Streams.Stream_Element_Array (1 .. Local'Length); > pragma Import (Ada, Output); > for Output'Address use Local'Address; > begin -- Send > GNAT.Serial_Communication.Write (P, Output)? > end Send; If you wanted optimize it, then Cmd and LF should be written in separate calls rather than making a local copies. A case when a copying makes sense is in a packet-oriented protocol. Which is not the case here since streams are used. Maybe it is still packet-oriented because of the USB device class, but then interfacing it through a stream is inappropriate. P.S. I don't see anything wrong with the original code. Stream attributes not to be trusted in general. An explicit conversion is clearer and cleaner, IMO. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de