[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Confuse-devel] Re: [PATCH 1/7] confuse: ISO C90 does not support th
From: |
Martin Hedenfalk |
Subject: |
Re: [Confuse-devel] Re: [PATCH 1/7] confuse: ISO C90 does not support the ???%lf??? printf format |
Date: |
Mon, 12 Jul 2010 09:13:15 +0200 |
12 jul 2010 kl. 08.40 skrev Carlo Marcelo Arenas Belon:
> 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 :
We're not using any long doubles, so any %lf formats should just drop the 'l'
modifier.
>> 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?
We don't want any undefined behaviour. Ok.
-martin