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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c4d884378fc6b03c X-Google-Attributes: gid103376,public From: adam@irvine.com (Adam Beneschan) Subject: Re: Two questions Date: 1996/11/11 Message-ID: <5689e0$hah@krusty.irvine.com>#1/1 X-Deja-AN: 196007180 references: <561dfo$h2g@news2.delphi.com> organization: /z/news/newsctl/organization newsgroups: comp.lang.ada Date: 1996-11-11T00:00:00+00:00 List-Id: In article <561dfo$h2g@news2.delphi.com> tmoran@bix.com writes: >The Ada idiom for > char str[20]; > sprintf(&str, "variable %s = %d", name, x); >would be something like: >declare > str:constant string := "variable " & name & " =" & integer'image(x); >begin > ... >Or, since you can return whole strings from functions, you can have > ... return "variable " & name & " =" & integer'image(x); Well, not exactly. Assuming "x" may contain any 32-bit value including -2**31, there's not enough room in "str" in the C example to hold everything. So the true Ada idiom should be something like: declare str : constant string := "variable " & name & " =" & integer'image(x); begin Write_Trash_All_Over_Your_Stack; I suspect this is an idiom that would be highly familiar to C programmers. :) -- Adam