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,235855e3822c83d1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.205.131.16 with SMTP id ho16mr1180920bkc.3.1335518298833; Fri, 27 Apr 2012 02:18:18 -0700 (PDT) Path: h15ni170974bkw.0!nntp.google.com!news2.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!weretis.net!feeder4.news.weretis.net!nuzba.szn.dk!news.jacob-sparre.dk!munin.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Importing C function with variable argument list Date: Fri, 27 Apr 2012 11:18:15 +0200 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: <87wr51a5yg.fsf@adaheads.sparre-andersen.dk> References: <610ee323-4c7f-413d-8568-aed4955f5152@z38g2000vbu.googlegroups.com> <1288794.275.1334249936588.JavaMail.geo-discussion-forums@ynlp2> NNTP-Posting-Host: 212.27.17.251.bredband.3.dk Mime-Version: 1.0 X-Trace: munin.nbi.dk 1335518297 5076 212.27.17.251 (27 Apr 2012 09:18:17 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Fri, 27 Apr 2012 09:18:17 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:RSrNT1X8xdwUA3MaZlduCpZK0RA= Content-Type: text/plain; charset=us-ascii Date: 2012-04-27T11:18:15+02:00 List-Id: Natasha Kerensikova wrote: > Another significant difference between varargs and regular arguments > is "type promotion". Briefly, char and short types are promoted to int > when they are part of a variadic argument, while they are not when > they are an explicit argument. > > So the following will probably fail more reliably than previous > examples: I'm afraid I have to disappoint you. Your example (here with test driver) works fine on Debian/stable (armv6l): % cat c_varargs.adb with Interfaces.C; procedure C_Varargs is function Print_Short (Format : in Interfaces.C.char_array; Value : in Interfaces.C.short) return Interfaces.C.int; pragma Import (C, Print_Short, "printf"); use type Interfaces.C.char_array; Result : Interfaces.C.int; begin Result := Print_Short ("%hd" & Interfaces.C.char'Val (10), 42); end C_Varargs; % gnatmake c_varargs [...] % ./c_varargs 42 % Greetings, Jacob -- "In space, no-one can press CTRL-ALT-DEL" -- An Ada programmer