This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: fprintf control from Environment variable.
- From: Kalle Olavi Niemitalo <kon at iki dot fi>
- To: naveen yadav <yad dot naveen at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 09 Oct 2012 10:18:51 +0300
- Subject: Re: fprintf control from Environment variable.
- Keywords: fprintf,builtin,inline,Wformat
- References: <CAJ8eaTxfW_sJ9=ZYKvYwwnrgckxtmNopQ3NYG215+fZ1rBvktA@mail.gmail.com>
naveen yadav <yad.naveen@gmail.com> writes:
> I checked that for fprintf() call if stream is other then stdout or
> stderr then code flows comes to vfprintf() function and if stream is
> stdout or stderr then code flow is different and fwrite() function is
> getting called.
Use gcc -fno-builtin-fprintf to disable this transformation.
However, that option also makes GCC not warn about calls like
fprintf(stdout, "hahaha%s\n") where the format string does not
match the argument list. You can restore those warnings by
declaring fprintf with __attribute__((format(printf, 2, 3))).
<stdio.h> of glibc apparently does not do that.
According to gcc/builtins.c (avoid_folding_inline_builtin),
another way to disable the transformation would be to declare
fprintf as an inline __attribute__((always_inline)) function.
However, that causes an error if compiling with gcc -O2.
If you only declare fprintf without a function body:
In file included from test-builtin-fprintf.c:1:0:
/usr/include/stdio.h:353:12: error: inlining failed in call to always_inline âfprintfâ: function body not available
test-builtin-fprintf.c:24:10: error: called from here
If you define fprintf with a function body:
In file included from test-builtin-fprintf.c:1:0:
test-builtin-fprintf.c: In function âfprintfâ:
/usr/include/stdio.h:353:12: error: function âfprintfâ can never be inlined because it uses variable argument lists