This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fprintf control from Environment variable.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]