PDA

Prikaži potpunu verziju : C++ Warnings?


clzola
15.10.2011, 15:36
line:

long long X;
scanf("%lld", &X);


warning:

warning: unknown conversion type character 'l' in format
warning: too many arguments for format


Prije nisam puno obracao paznju na ovo upozorenje, ali me sad interesuje zasto se pojavljuje i kako da ga maknem. Kad sam ucio 'long long' profesor mi je rekao da se za unos long long broja koristi %lld. :/ :?

Andross
15.10.2011, 16:33
Zavisi od kompajlera i runtime biblioteka, negde ce da baca upozorenje negde nece.

Geomaster
15.10.2011, 17:14
Zavisi koja standardna biblioteka je u pitanju. Po onome što vidim na netu, M$-ov msvcrt koristi %I64d, dok gcc-ove biblioteke koriste %lld. AFAIK. Overi ovo (http://cboard.cprogramming.com/c-programming/92920-scanf-long-long.html).

EDIT: man page za glibc-ov scanf kaže ovo:

l Indicates either that the conversion will be one of d, i, o, u,
x, X, or n and the next pointer is a pointer to a long int or
unsigned long int (rather than int), or that the conversion will
be one of e, f, or g and the next pointer is a pointer to double
(rather than float). Specifying two l characters is equivalent
to L. If used with %c or %s the corresponding parameter is con‐
sidered as a pointer to a wide character or wide-character
string respectively.

L Indicates that the conversion will be either e, f, or g and the
next pointer is a pointer to long double or the conversion will
be d, i, o, u, or x and the next pointer is a pointer to long
long.

clzola
15.10.2011, 17:45
Koristim CodeBlocks IDE a uz njega dodje gcc 4.4.1 .. :/?

edit: stavio sam %I64d i sad ne prijavljuje warning

Geomaster
15.10.2011, 18:35
Nisam dobio nikakav warning sa %L.

geomaster@geo-u135:~/Projects/test/clzola$ cat >test.c
#include <stdio.h>

main()
{
long long x;
scanf("%Ld", &x);
printf("Your number: %Ld", x);
}
geomaster@geo-u135:~/Projects/test/clzola$ gcc -o test test.c
geomaster@geo-u135:~/Projects/test/clzola$ ./test
123456789
Your number: 123456789

Belphegor
15.10.2011, 20:05
Ne znam kako je sa gcc-om ali kod M$ zavisi od warning levela postavljenog u opcijama koji ce da prijavi. Ja obicno stavim na 4 (default je 3):
http://www.dodaj.rs/t/1E/bJ/4bejyzri/wlevel.jpg (http://www.dodaj.rs/?1E/bJ/4bejyzri/wlevel.jpg)
mada moze i sa pragma direktivama ponaosob da se podesava.

btw. ovo radi i kod mene bez warninga M$, osim sto kaze da je scanf "unsafe".

#include <stdio.h>

int main()
{
long long x;
scanf("%Ld", &x);
printf("Your number: %Ld", x);
}