Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc compile error. expects argument of type ‘int’, but argument 2 has type ‘long long int’ #55

Open
jeffery9 opened this issue May 28, 2020 · 3 comments

Comments

@jeffery9
Copy link

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.11' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11)

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11) compile error.

ubuntu@VM-0-4-ubuntu:~/c4$ gcc -o c4 c4.c
c4.c: In function ‘next’:
c4.c:56:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
         printf("%d: %.*s", line, p - lp, lp);
                ^
c4.c:56:16: warning: field precision specifier ‘.*’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat=]
c4.c:62:34: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
           if (*le <= ADJ) printf(" %d\n", *++le); else printf("\n");
                                  ^

@benknoble
Copy link

I got it working under gcc-9 but not clang or older gcc.

@andrakis
Copy link

This is a warning, not an error. There do seem to be some cases where a multi-parameter printf will fail to print some integers, but in general everything still works.

These could be changed to %ld or something, but they were likely left so that it would still work on 32bit platforms. Though, this seems to be broken as of 2feb8c0 as the target number type is too large.

For now, you could ignore the warnings (and don't compile with warnings as errors). You could also turn off the warning itself with -Wno-format .

@benknoble
Copy link

Just realizing I misread the issue: my clang complains that main cannot have long long as the first argument, only int.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants