From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Re: Importing C function with variable argument list
Date: Fri, 27 Apr 2012 11:18:15 +0200
Date: 2012-04-27T11:18:15+02:00 [thread overview]
Message-ID: <87wr51a5yg.fsf@adaheads.sparre-andersen.dk> (raw)
In-Reply-To: slrnjpklu5.1lme.lithiumcat@sigil.instinctive.eu
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
next prev parent reply other threads:[~2012-04-27 9:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-10 9:21 Importing C function with variable argument list Maxim Reznik
2012-04-10 11:22 ` Patrick
2012-04-10 13:09 ` Maxim Reznik
2012-04-10 13:50 ` Georg Bauhaus
2012-04-10 13:18 ` Markus Schöpflin
2012-04-10 16:47 ` Simon Wright
2012-04-12 10:08 ` Markus Schöpflin
2012-04-12 16:58 ` Adam Beneschan
2012-04-12 20:47 ` Randy Brukardt
2012-04-13 8:43 ` Markus Schöpflin
2012-04-13 23:01 ` Randy Brukardt
2012-04-27 8:24 ` Natasha Kerensikova
2012-04-27 9:18 ` Jacob Sparre Andersen [this message]
2012-04-27 16:48 ` Natasha Kerensikova
2012-05-03 20:15 ` sbelmont700
2012-05-13 4:18 ` David Thompson
2012-05-13 9:03 ` Simon Wright
2012-05-13 17:01 ` Jeffrey Carter
2012-05-13 18:20 ` Simon Wright
2012-05-13 19:11 ` Jeffrey Carter
2012-05-13 19:55 ` Ludovic Brenta
2012-05-14 0:52 ` Jeffrey Carter
2012-05-13 21:12 ` Simon Wright
2012-05-13 23:57 ` Georg Bauhaus
2012-05-14 0:54 ` Jeffrey Carter
2012-05-14 8:10 ` Nomen Nescio
2012-05-14 15:21 ` Natasha Kerensikova
2012-05-14 20:53 ` sbelmont700
2012-04-13 4:08 ` Tero Koskinen
2012-04-13 8:04 ` Markus Schöpflin
2012-04-10 20:02 ` Tero Koskinen
2012-04-13 3:28 ` Tero Koskinen
2012-04-10 20:25 ` sbelmont700
2012-04-11 23:24 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox