Web lists-archives.com

Re: [Mingw-users] bizarre problem, need help from a mingw developer




On 09-Mar-2016 10:35, Keith Marshall wrote:
> (My own
> preference is to use a gcc option, such as -ansi or -posix, or any of
> the -std= options which implies __STRICT_ANSI__

You mean like: -std=c99  ???

That does not work, at least on the mingw I have installed.  With NO
flags one gets the C99 behavior:

> gcc -o printf_bug printf_bug.c
> printf_bug
val 1.000000
esc 0.000000 cos 1.000000 sin 0.000000 -sin 0.000000 -cos -1.000000
esc 0.000000 cos 1.000000 sin 0.000000 -sin 0.000000 -cos -1.000000

but when it is explicitly requested, with -std=c99,
-D__USE_MINGW_ANSI_STDIO, or both it gives the other one.  Example:

> gcc -std=c99 -o printf_bug printf_bug.c
> printf_bug
val 0.000000
esc 0.000000 cos 0.000000 sin 0.000000 -sin 0.000000 -cos 0.000000
esc 0.000000 cos 0.000000 sin 0.000000 -sin 0.000000 -cos 0.000000


If the choice of printf() was fully specified at compilation it would 
not explain the next example pair, where the function name is presumably 
set in stone when the object file is created:

> gcc -c -o printf_bug.o printf_bug.c
> gcc -o printf_bug printf_bug.o
> printf_bug
val 1.000000
esc 0.000000 cos 1.000000 sin 0.000000 -sin 0.000000 -cos -1.000000
esc 0.000000 cos 1.000000 sin 0.000000 -sin 0.000000 -cos -1.000000

yet...

> gcc -o printf_bug printf_bug.o  -Lc:\progs\devlibs61/lib -lpoppler
> printf_bug
val 0.000000
esc 0.000000 cos 0.000000 sin 0.000000 -sin 0.000000 -cos 0.000000
esc 0.000000 cos 0.000000 sin 0.000000 -sin 0.000000 -cos 0.000000

So, I tried compiling the test program with -std=C99, -ansi with -S and 
the
outputs were the same.  Leaving off the standard they differed.  The 
"default"
has only these printf symbols (ie grep print printf_bug.S):
   _printf
   _sprintf

but -ansi/-std=c99 have these
   _printf
   _sprintf
   __mingw_vprintf
   __mingw_vsprintf

The ones that are broken (-std=c99, etc.) define _printf and _sprintf in 
terms of ___mingw_vprintf right at the start.  The one that works (no 
language standard
specified) does not define _printf, apparently leaving it for the 
linker.  That would explain how it could be broken later by adding in 
poppler.

This may wrap, but the code in the -std=c99 ones for the _sprintf 
definition
is this (_printf is similar):

LFE1:
         .def    _sprintf;       .scl    3;      .type   32;     .endef
_sprintf:
LFB2:
         .cfi_startproc
         pushl   %ebp
         .cfi_def_cfa_offset 8
         .cfi_offset 5, -8
         movl    %esp, %ebp
         .cfi_def_cfa_register 5
         pushl   %ebx
         subl    $36, %esp
         leal    16(%ebp), %edx
         leal    -12(%ebp), %eax
         movl    %edx, (%eax)
         movl    -12(%ebp), %eax
         movl    %eax, 8(%esp)
         movl    12(%ebp), %eax
         movl    %eax, 4(%esp)
         movl    8(%ebp), %eax
         movl    %eax, (%esp)
         .cfi_offset 3, -12
         call    ___mingw_vsprintf
         movl    %eax, %ebx
         movl    %ebx, %eax
         addl    $36, %esp
         popl    %ebx
         .cfi_restore 3
         popl    %ebp
         .cfi_def_cfa 4, 4
         .cfi_restore 5
         ret
         .cfi_endproc

This is gcc 4.6.2, perhaps more recent mingw do this differently.

Regards,

David Mathog
mathog@xxxxxxxxxxx
Manager, Sequence Analysis Facility, Biology Division, Caltech

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe