confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Confuse-devel] Re: [PATCH 1/7] confuse: ISO C90 does not support the ??


From: Carlo Marcelo Arenas Belon
Subject: [Confuse-devel] Re: [PATCH 1/7] confuse: ISO C90 does not support the ???%lf??? printf format
Date: Mon, 12 Jul 2010 06:40:30 +0000
User-agent: Mutt/1.5.18 (2008-05-17)

On Sat, Mar 27, 2010 at 03:08:28AM -0700, Carlo Marcelo Arenas Belon wrote:
>
> '%f' is valid for float and double, while '%Lf' is needed for long double
> leaving this as a undefined behaviour for C90 and ignored in C99 as shown
> by :
> 
>   confuse.c:1410: warning: ISO C90 does not support the ???%lf??? printf 
> format

this will break, at least in mingw32 when using -std=c89 as shown by (not
confuse specific but still a good example of what would happen with
cfg_opt_nprint_*)

  $ cat > float.c 
  #include <stdio.h>

  int main(int argc, char *argv[])
  {
    float f = 3.1415926;
    double d = 3.1415926;

    printf("f = %f, d = %lf\n", f, d);
    return 0;
  }^D
  $ i686-pc-mingw32-gcc -std=c89 -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 
-fexceptions --param=ssp-buffer-size=4 -mms-bitfields float.c -o float.exe
  $ ./float.exe 
  f = 3.141593, d = 0.000000

> diff --git a/src/confuse.c b/src/confuse.c
> index 003d0b9..6e7a0ef 100644
> --- a/src/confuse.c
> +++ b/src/confuse.c
> @@ -1407,7 +1407,7 @@ DLLIMPORT void cfg_opt_nprint_var(cfg_opt_t *opt, 
> unsigned int index, FILE *fp)
>              fprintf(fp, "%ld", cfg_opt_getnint(opt, index));
>              break;
>          case CFGT_FLOAT:
> -            fprintf(fp, "%lf", cfg_opt_getnfloat(opt, index));
> +            fprintf(fp, "%f", cfg_opt_getnfloat(opt, index));
>              break;
>          case CFGT_STR:
>              str = cfg_opt_getnstr(opt, index);
> -- 

this snippet should prevent that, but wasn't committed as part of this patch
in 6d5335a8ac0ea6bdb553931a29bef0e2d21d4e3e

anyone has any objections or is depending on the undefined behaviour that
"%lf" has?

Carlo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]