Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
On Thu, Aug 27, 2020 at 8:45 AM Ruben Van Boxem wrote: > > Op do 27 aug. 2020 om 07:18 schreef Vincent Torri : > > > On Thu, Aug 27, 2020 at 3:24 AM Liu Hao wrote: > > > > > > 在 2020/8/27 上午2:06, Vincent Torri 写道: > > > > > > > > i've checked in cmd too, same result > > > > > > > > But there is anyway something strange to me : > > > > > > > > myprog_gcc.exe and myprog_vs are *both* run in MSYS2, and the result > > > > is different. So I don't think it's related to path translation. It > > > > would suggest something related to how gcc builds the binary > > > > > > > > > > > > > In 'mingw-w64-crt/crt/crtexe.c' , `argv` is initialized by the function > > `__getmainargs()` which is imported from MSVCRT. VC > > > uses new versions of runtime libraries so it'd be MSVCR100, MSVCR120, > > etc. There might be some differences in the > > > aforementioned function. > > > > that makes sense. Is it possible to tell gcc to use msvcr*.dll instead > > of msvcrt.dll ? > > > > Asking where the difference comes from is a useful question. > Relying on these kinds of details to make Unicode work is not IMHO. > > If you want correct handling of unicode path names, call the appropriate > functions. > Either compile the GCC code with -municode and use _wmain, or call > CommandLineToArgvW with GetCommandLineW and then a _wfopen. > Windows is an obtuse platform, and its shells do not support the Unix-wide > UTF-8 assumption. I will try this, thank you Vincent Torri ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
Op do 27 aug. 2020 om 07:18 schreef Vincent Torri : > On Thu, Aug 27, 2020 at 3:24 AM Liu Hao wrote: > > > > 在 2020/8/27 上午2:06, Vincent Torri 写道: > > > > > > i've checked in cmd too, same result > > > > > > But there is anyway something strange to me : > > > > > > myprog_gcc.exe and myprog_vs are *both* run in MSYS2, and the result > > > is different. So I don't think it's related to path translation. It > > > would suggest something related to how gcc builds the binary > > > > > > > > > In 'mingw-w64-crt/crt/crtexe.c' , `argv` is initialized by the function > `__getmainargs()` which is imported from MSVCRT. VC > > uses new versions of runtime libraries so it'd be MSVCR100, MSVCR120, > etc. There might be some differences in the > > aforementioned function. > > that makes sense. Is it possible to tell gcc to use msvcr*.dll instead > of msvcrt.dll ? > Asking where the difference comes from is a useful question. Relying on these kinds of details to make Unicode work is not IMHO. If you want correct handling of unicode path names, call the appropriate functions. Either compile the GCC code with -municode and use _wmain, or call CommandLineToArgvW with GetCommandLineW and then a _wfopen. Windows is an obtuse platform, and its shells do not support the Unix-wide UTF-8 assumption. Relying on locally set code pages and how shells interpret them is a recipe for disaster, not to mention an incredible waste of time and effort. Ruben ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
On Thu, Aug 27, 2020 at 3:24 AM Liu Hao wrote: > > 在 2020/8/27 上午2:06, Vincent Torri 写道: > > > > i've checked in cmd too, same result > > > > But there is anyway something strange to me : > > > > myprog_gcc.exe and myprog_vs are *both* run in MSYS2, and the result > > is different. So I don't think it's related to path translation. It > > would suggest something related to how gcc builds the binary > > > > > In 'mingw-w64-crt/crt/crtexe.c' , `argv` is initialized by the function > `__getmainargs()` which is imported from MSVCRT. VC > uses new versions of runtime libraries so it'd be MSVCR100, MSVCR120, etc. > There might be some differences in the > aforementioned function. that makes sense. Is it possible to tell gcc to use msvcr*.dll instead of msvcrt.dll ? Vincent Torri ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
On Thu, Aug 27, 2020 at 2:19 AM sisyphus wrote: > > On Wed, Aug 26, 2020 at 7:01 PM Vincent Torri > wrote: > > > - > > #include > > > > #include > > > > int main(int argc, char* argv[]) > > { > > FILE* f; > > if (argc < 2) > > { > > printf("%s\n", argv[0]); > > return 1; > > } > > > > f = fopen(argv[1], "rb"); > > if (!f) > > printf("bad\n"); > > else > > printf("good\n"); > > return 0; > > } > > - > > > > > Looking at the code, I see no need for the inclusion of windows.h. > I take it that the inclusion of windows.h is merely an oversight, and that > the differing behaviour does not depend on it ? it's just that i also tried with CreateFile, and remote it, i've forgotten to remove windows.h inclusion Vincent Torri ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
在 2020/8/27 上午2:06, Vincent Torri 写道: > > i've checked in cmd too, same result > > But there is anyway something strange to me : > > myprog_gcc.exe and myprog_vs are *both* run in MSYS2, and the result > is different. So I don't think it's related to path translation. It > would suggest something related to how gcc builds the binary > In 'mingw-w64-crt/crt/crtexe.c' , `argv` is initialized by the function `__getmainargs()` which is imported from MSVCRT. VC uses new versions of runtime libraries so it'd be MSVCR100, MSVCR120, etc. There might be some differences in the aforementioned function. -- Best regards, LH_Mouse signature.asc Description: OpenPGP digital signature ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
On Wed, Aug 26, 2020 at 7:01 PM Vincent Torri wrote: > - > #include > > #include > > int main(int argc, char* argv[]) > { > FILE* f; > if (argc < 2) > { > printf("%s\n", argv[0]); > return 1; > } > > f = fopen(argv[1], "rb"); > if (!f) > printf("bad\n"); > else > printf("good\n"); > return 0; > } > - > > Looking at the code, I see no need for the inclusion of windows.h. I take it that the inclusion of windows.h is merely an oversight, and that the differing behaviour does not depend on it ? Cheers, Rob ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
On Wed, Aug 26, 2020 at 4:38 PM Liu Hao wrote: > > 在 2020/8/26 18:05, Vincent Torri 写道: > > > > the file is : Moș_Crăciun_cântece.txt > > I print it in the prog with printf : > > > > $ ./fopen.exe Moș_Crăciun_cântece.txt > > bad > > Mo?_Craciun_cÔntece.txt > > > > Would you please check whether the program behaves as expected in CMD? > > MSYS2 performs some path translations, but I am not clear whether it has > anything to do with the encoding. I suspect it has, > because Linux programs generally expects UTF-8, so there must be kind of > conversion from UTF-8 to ACP for arguments passed > to native programs. i've checked in cmd too, same result But there is anyway something strange to me : myprog_gcc.exe and myprog_vs are *both* run in MSYS2, and the result is different. So I don't think it's related to path translation. It would suggest something related to how gcc builds the binary Vincent Torri ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
在 2020/8/26 18:05, Vincent Torri 写道: > > the file is : Moș_Crăciun_cântece.txt > I print it in the prog with printf : > > $ ./fopen.exe Moș_Crăciun_cântece.txt > bad > Mo?_Craciun_cÔntece.txt > Would you please check whether the program behaves as expected in CMD? MSYS2 performs some path translations, but I am not clear whether it has anything to do with the encoding. I suspect it has, because Linux programs generally expects UTF-8, so there must be kind of conversion from UTF-8 to ACP for arguments passed to native programs. -- Best regards, LH_Mouse signature.asc Description: OpenPGP digital signature ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
On Wed, Aug 26, 2020 at 11:29 AM Liu Hao wrote: > > 在 2020/8/26 下午5:00, Vincent Torri 写道: > > > > So, I have a file which has a romanian symbol : Moș.txt > > > > 1) if I run in MSYS2 ./myprog_gcc (compiled with gcc) Moș.txt, "bad" > > is displayed > > > > 2) if I run in MSYS2 ./myprog_vs (compiled with VSc) Moș.txt, "good" > > is displayed > > > > does someone have an idea why there is such difference ? > > > > I suspect this has something to do with the encoding of paths, as `fopen()` > accepts paths in your system's DBCS encoding > (a.k.a. ANSI code page). > > I cannot have your program work in any way on my Windows 7 in Simplified > Chinese (code page 936). The path passed to > `fopen()` is `Mo?.txt`. That is, the `ș` character which does not exist in > CP936 gets replaced by a question mark, and is > thus never a valid filename. > > It might help if you print the argument passed to `fopen()` and see whether > it is corrupted or not. the file is : Moș_Crăciun_cântece.txt I print it in the prog with printf : $ ./fopen.exe Moș_Crăciun_cântece.txt bad Mo?_Craciun_cÔntece.txt Vinent Torri ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] runtime difference between code compiled with VS and gcc
在 2020/8/26 下午5:00, Vincent Torri 写道: > > So, I have a file which has a romanian symbol : Moș.txt > > 1) if I run in MSYS2 ./myprog_gcc (compiled with gcc) Moș.txt, "bad" > is displayed > > 2) if I run in MSYS2 ./myprog_vs (compiled with VSc) Moș.txt, "good" > is displayed > > does someone have an idea why there is such difference ? > I suspect this has something to do with the encoding of paths, as `fopen()` accepts paths in your system's DBCS encoding (a.k.a. ANSI code page). I cannot have your program work in any way on my Windows 7 in Simplified Chinese (code page 936). The path passed to `fopen()` is `Mo?.txt`. That is, the `ș` character which does not exist in CP936 gets replaced by a question mark, and is thus never a valid filename. It might help if you print the argument passed to `fopen()` and see whether it is corrupted or not. -- Best regards, LH_Mouse signature.asc Description: OpenPGP digital signature ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
[Mingw-w64-public] runtime difference between code compiled with VS and gcc
hello (sorry, the previous mail has wrong topic) I have this simple code : - #include #include int main(int argc, char* argv[]) { FILE* f; if (argc < 2) { printf("%s\n", argv[0]); return 1; } f = fopen(argv[1], "rb"); if (!f) printf("bad\n"); else printf("good\n"); return 0; } - of course, both compile with VS and on MSYS2+mingw-w64 The problem is runtime. I don't know if it is important or not, but I am running Windows 10, french edition. So, I have a file which has a romanian symbol : Moș.txt 1) if I run in MSYS2 ./myprog_gcc (compiled with gcc) Moș.txt, "bad" is displayed 2) if I run in MSYS2 ./myprog_vs (compiled with VSc) Moș.txt, "good" is displayed does someone have an idea why there is such difference ? thank you Vincent Torri ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
[Mingw-w64-public] runtime difference betwwith VS an een code compiled with gcc and VS
Hello I have this simple code : - #include #include int main(int argc, char* argv[]) { FILE* f; if (argc < 2) { printf("%s\n", argv[0]); return 1; } f = fopen(argv[1], "rb"); if (!f) printf("bad\n"); else printf("good\n"); return 0; } - of course, both compile with VS and on MSYS2+mingw-w64 The problem is runtime. I don't know if it is important or not, but I am running Windows 10, french edition. So, I have a file which has a romanian symbol : Moș.txt 1) if I run in MSYS2 ./myprog_gcc (compiled with gcc) Moș.txt, "bad" is displayed 2) if I run in MSYS2 ./myprog_vs (compiled with VSc) Moș.txt, "good" is displayed does someone have an idea why there is such difference ? thank you Vincent Torri ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public