On May 10, 9:13 am, "stefan.istr...@gmail.com"
<stefan.istr...@gmail.comwrote:
I have a short int variable and I'm trying to read it with
scanf("%d",&x);
but I'm getting a warning message which sounds like this:
warning: format '%d' expects type 'int*', but argument 2 has type
'short int*'
How can I avoid this warning and still read with "scanf"? I mention
that I don't want to use "cout". Maybe this problem is for C (not for C
++), but the program is in C++ because i use after this the Standard
Template Library.
Let me get this straight. You are using a tool which is error
prone, complex, and difficult, and you don't want to replace it
with one which is simple to use and robust. Strange.
In scanf, you have to specify the type of the argument exactly,
and it must match the type of the target. If you say "%d", then
the argument must be an int*; anything else is undefined
behavior. Similarly, for "%hhd", it must be a signed char*, for
"%hd" a short*, for "%ld" a long*, for "%lld" a long long*, for
"%jd" an intmax_t*, and for "%td" a ptrdiff_t. And woe be it if
the type your interested in is a typedef in a library, which
might change in a future version. (And can anyone really
believe that learning all of these exotic prefixes is in any way
intuitive?)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34