How do you call scanf from Ada? That is, presumably with an appropriate pragma import declaration, but what would the declaration look like?
(I’m interested in how to call C functions of the more unruly variety from Ada, not how to parse strings per se, so I’m not looking for a pure Ada solution. My setup is Gnat, Ubuntu Linux, x64 if it makes a difference.)
This paper points out that
The same would be true of
scanf(), which with Ada 2012 has the added bonus of letting you choose betweenoutandaccessparameter specs (in earlier revisions, you had to useaccessbecause functions weren’t allowed to haveoutparameters).In addition, I don’t believe it’s required that the C compiler has to use the same parameter passing mechanisms for variadic functions as it does for ordinary ones (the reference hints at this, and I recall but can’t now find a recent conversation on these lines).
That said, here’s an example which appears to work fine on Mac OS X with GCC 4.6.0:
(not sure about the
\nin the format parameter!)