[gdal-dev] Question about json-c mods in changeset r18545

Even Rouault even.rouault at mines-paris.org
Sat Apr 28 09:07:15 EDT 2012


Le samedi 28 avril 2012 14:09:35, Mateusz Loskot a écrit :
> Even, Folks,
> 
> I noticed your commit r18545 in json-c version maintained in GDAL tree [1].
> 
> It says: "bug fix submitted to jsonc maintener now"
> I don't know the details who, how and where this was submitted to the
> upstream,

Well, I submitted it, but I don't recall if I followed if it was accepted or

> 
> I do not use MinGW, but could you or anyone who is concerned about MinGW
> support try the following test and report any errors occurred?
> 
> https://gist.github.com/2518402

I've tried with 2 mingw versions, and with both the %lf %lg don't work well 
(although the output is a bit different)

$ gcc --version
gcc.exe (GCC) 3.4.5 (mingw-vista special r3)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ./test.exe
n1=-1375090688, n2=302
dnum=1.3e+012, dden=1.99989e+012, dpercent=65.00
(l) ldnum=-3.07944e-196, ldden=-9.36335e-097, ldpercent=0.00
(L) ldnum=-3.07944e-196, ldden=-9.36335e-097, ldpercent=0.00



$ /e/mingw-new/bin/gcc --version
gcc.exe (GCC) 4.5.0
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ PATH=/e/MinGW-new/bin:$PATH gcc test.c -O2 -Wall -o test.exe
test.c: In function 'main':
test.c:16:1: warning: format '%ld' expects type 'long int', but argument 2 has 
type 'int64_t'
test.c:16:1: warning: format '%ld' expects type 'long int', but argument 3 has 
type 'int64_t'
test.c:18:1: warning: format '%lg' expects type 'double', but argument 2 has 
type 'long double'
test.c:18:1: warning: format '%lg' expects type 'double', but argument 3 has 
type 'long double'
test.c:18:1: warning: format '%4.2lf' expects type 'double', but argument 4 
has type 'long double'
test.c:19:1: warning: unknown conversion type character 'L' in format
test.c:19:1: warning: unknown conversion type character 'L' in format
test.c:19:1: warning: unknown conversion type character 'L' in format
test.c:19:1: warning: too many arguments for format

$ ./test.exe
n1=-1375090688, n2=302
dnum=1.3e+012, dden=1.99989e+012, dpercent=65.00
(l) ldnum=-3.07944e-196, ldden=-9.36336e-097, ldpercent=65.00
(L) ldnum=-3.07944e-196, ldden=-9.36336e-097, ldpercent=65.00

My conclusion is that %lf or %lg is unnecessary (and unspecified by the 
standards) when passing a double. When you specify %f in printf, the compiler 
naturally expects a double (and if you provide a float, due to the fact that it 
is a varags, it is automatically promoted to double). There is often 
confusion, because in sscanf, %f expects a pointer to a float, whereas %lf 
expects a pointer to a double. But printf is different...

> 
> (copy at http://codepad.org/users/mloskot)
> 
> The json-c has been updated and improved significantly between 0.9 and
> the upcoming 1.0.
> My aim is to push as many GDAL-derived json-c fixes as possible to the
> json-c upstream, then update json-c in GDAL with the upstream.
> 
> [1]
> http://trac.osgeo.org/gdal/changeset/18545/trunk/gdal/ogr/ogrsf_frmts/geoj
> son/jsonc?rev=18545 [2]
> https://groups.google.com/forum/?fromgroups#!topic/json-c/2w3zoKbPwJU
> 
> Best regards,


More information about the gdal-dev mailing list