Re: [Mingw-w64-public] C++ cout executable size
I was able to reproduce your problem. The issue is that you declared a variable named stdout, which is a name used by the C standard. Just rename that variable. --David On Sun, Jun 4, 2017 at 8:31 AM, bob bywrote: > 2017-06-02 15:47 GMT+04:00 bob by > >> Can somebody here write a replacement for the standard cout, that will be >> able to print strings and integers, and internally will just redirect to >> puts and itoa? I'm only starting with C++, I'm not sure how to do it. >> > > So, I'm trying to do this, This code seems to more or less work, but adding > #include causes compile error at the HANDLE. Error says > "declaration of _imp__iob as array of references". > > I kind of want to try out std::string, even though I don't know how it's > different from char*. > > #include > > class cout_c > { > public: > HANDLE stdout; > void init() > { > stdout = GetStdHandle(STD_OUTPUT_HANDLE); > } > cout_c& operator<<(char* s) > { > WriteFile(stdout, s, strlen(s), NULL, NULL); > return *this; > } > }; > > cout_c cout; > > int main() > { > cout.init(); > cout << "1234567890"; > } > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > ___ > Mingw-w64-public mailing list > Mingw-w64-public@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mingw-w64-public -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] C++ cout executable size
2017-06-02 15:47 GMT+04:00 bob by> Can somebody here write a replacement for the standard cout, that will be > able to print strings and integers, and internally will just redirect to > puts and itoa? I'm only starting with C++, I'm not sure how to do it. > So, I'm trying to do this, This code seems to more or less work, but adding #include causes compile error at the HANDLE. Error says "declaration of _imp__iob as array of references". I kind of want to try out std::string, even though I don't know how it's different from char*. #include class cout_c { public: HANDLE stdout; void init() { stdout = GetStdHandle(STD_OUTPUT_HANDLE); } cout_c& operator<<(char* s) { WriteFile(stdout, s, strlen(s), NULL, NULL); return *this; } }; cout_c cout; int main() { cout.init(); cout << "1234567890"; } -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *
I sent patch casting to PUWSTR_C half hour after first message when I noticed how stupid it was before. Should still apply cleanly (attachment has wrong name): https://sourceforge.net/p/mingw-w64/mailman/message/35770400/ -- Original Message -- Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t * Date: Sun, 04 Jun 2017 12:40:05 + To: Mingw-w64-public From: Norbert Pfeiler > 1st point was to use PUWSTR_C instead of wchar_t * for the cast, still > stands. > 2nd point was to »to avoid further warnings« and i would like to – once > again – vote to avoid union casts. > > As far as i know there is no reason to believe that -Wcast-qual (as well as > -Wsystem-headers) will be a default warning anytime soon. And even then it > would be just a warning but still standards-conforming code (which is also > a reason for it not to become a default warning). > > A C-style cast is perfectly appropriate here, no union needed. > > FTR, it’s not only Clang which doesn’t accept the pre-patch code, GCC > errors too. > > Best, Norbert. > > On Sun, Jun 4, 2017 at 12:18 PM Mateusz Mikuławrote: > >> Anything to improve? >> >> From 05bc4cbc93f5f9942fc28a578dc1afa68d69daa2 Mon Sep 17 00:00:00 2001 >> From: Mateusz Mikula >> Date: Sun, 4 Jun 2017 11:33:22 +0200 >> Subject: [PATCH] cast ua_wcschr and ua_wcsrchr returns when WSTR_ALIGNED is >> true >> >> Clang doesn't allow implicit conversion form "const wchar_t *" to >> "PUWSTR_C" (aka wchar_t *) >> >> Signed-off-by: Mateusz Mikula >> --- >> mingw-w64-headers/include/stralign.h | 15 +-- >> 1 file changed, 13 insertions(+), 2 deletions(-) >> >> diff --git a/mingw-w64-headers/include/stralign.h >> b/mingw-w64-headers/include/stralign.h >> index 9b5637d6..4b157c27 100644 >> --- a/mingw-w64-headers/include/stralign.h >> +++ b/mingw-w64-headers/include/stralign.h >> @@ -117,12 +117,23 @@ extern "C" { >>size_t ua_wcslen(PCUWSTR String); >> >> #ifndef __CRT__NO_INLINE >> +union { >> + wchar_t *wcharPointer; >> + const wchar_t *constWcharPointer; >> +} cast; >> + >>__CRT_INLINE PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character) { >> -if(WSTR_ALIGNED(String)) return wcschr((PCWSTR)String,Character); >> +if(WSTR_ALIGNED(String)) { >> + cast.constWcharPointer = wcschr((PCWSTR)String,Character); >> + return cast.wcharPointer; >> +} >> return (PUWSTR_C)uaw_wcschr(String,Character); >>} >>__CRT_INLINE PUWSTR_C ua_wcsrchr(PCUWSTR String,WCHAR Character) { >> -if(WSTR_ALIGNED(String)) return wcsrchr((PCWSTR)String,Character); >> +if(WSTR_ALIGNED(String)) { >> + cast.constWcharPointer = wcsrchr((PCWSTR)String,Character); >> + return cast.wcharPointer; >> +} >> return (PUWSTR_C)uaw_wcsrchr(String,Character); >>} >> #if defined(__cplusplus) && defined(_WConst_Return) >> -- >> 2.12.1 >> >> >> >> -- Original Message -- >> Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and >> ua_wcsrchr returns to wchar_t * >> Date: Thu, 6 Apr 2017 11:48:24 +0200 >> To: Mingw-w64-public >> From: Kai Tietz >>> A cast via union looks like this: >>> type1 *foo(const type1 *my_const_ptr) >>> { >>> union { >>> type1 *t1; >>> const type1 *ct1; >>> } v; >>> v.ct1 = my_const_ptr; >>> return v.t1; >>> } >>> >>> The advantage of such a pattern is that no type conversion >>> errors/warnings are shown. So for casting from const to none-const, >>> this variant is to be preferred. (and it works for C, and C++!!!) >>> >>> Cheers, >>> Kai >>> >>> 2017-04-05 15:51 GMT+02:00 Mateusz Mikuła : > Hmm, using here "wchar_t *" as cast looks wrong. Actually we should > use anyway PUWSTR_C instead. I noticed it a bit too late and sent another patch casting to PUWSTR_C. > Nevertheless we can have here a const/none-const conversion (means > const specifiers for C-runtime function isn't regarded right?). I > would suggest to introduce a union-cast instead to avoid further > warnings instead. Conversion from const pointer to normal pointer is definitely unsafe but that's probably what GCC just did. I'm unsure what you mean by "union-cast" but you can commit your fix. >> -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public >> -- >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >>>
Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *
1st point was to use PUWSTR_C instead of wchar_t * for the cast, still stands. 2nd point was to »to avoid further warnings« and i would like to – once again – vote to avoid union casts. As far as i know there is no reason to believe that -Wcast-qual (as well as -Wsystem-headers) will be a default warning anytime soon. And even then it would be just a warning but still standards-conforming code (which is also a reason for it not to become a default warning). A C-style cast is perfectly appropriate here, no union needed. FTR, it’s not only Clang which doesn’t accept the pre-patch code, GCC errors too. Best, Norbert. On Sun, Jun 4, 2017 at 12:18 PM Mateusz Mikuławrote: > Anything to improve? > > From 05bc4cbc93f5f9942fc28a578dc1afa68d69daa2 Mon Sep 17 00:00:00 2001 > From: Mateusz Mikula > Date: Sun, 4 Jun 2017 11:33:22 +0200 > Subject: [PATCH] cast ua_wcschr and ua_wcsrchr returns when WSTR_ALIGNED is > true > > Clang doesn't allow implicit conversion form "const wchar_t *" to > "PUWSTR_C" (aka wchar_t *) > > Signed-off-by: Mateusz Mikula > --- > mingw-w64-headers/include/stralign.h | 15 +-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/mingw-w64-headers/include/stralign.h > b/mingw-w64-headers/include/stralign.h > index 9b5637d6..4b157c27 100644 > --- a/mingw-w64-headers/include/stralign.h > +++ b/mingw-w64-headers/include/stralign.h > @@ -117,12 +117,23 @@ extern "C" { >size_t ua_wcslen(PCUWSTR String); > > #ifndef __CRT__NO_INLINE > +union { > + wchar_t *wcharPointer; > + const wchar_t *constWcharPointer; > +} cast; > + >__CRT_INLINE PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character) { > -if(WSTR_ALIGNED(String)) return wcschr((PCWSTR)String,Character); > +if(WSTR_ALIGNED(String)) { > + cast.constWcharPointer = wcschr((PCWSTR)String,Character); > + return cast.wcharPointer; > +} > return (PUWSTR_C)uaw_wcschr(String,Character); >} >__CRT_INLINE PUWSTR_C ua_wcsrchr(PCUWSTR String,WCHAR Character) { > -if(WSTR_ALIGNED(String)) return wcsrchr((PCWSTR)String,Character); > +if(WSTR_ALIGNED(String)) { > + cast.constWcharPointer = wcsrchr((PCWSTR)String,Character); > + return cast.wcharPointer; > +} > return (PUWSTR_C)uaw_wcsrchr(String,Character); >} > #if defined(__cplusplus) && defined(_WConst_Return) > -- > 2.12.1 > > > > -- Original Message -- > Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and > ua_wcsrchr returns to wchar_t * > Date: Thu, 6 Apr 2017 11:48:24 +0200 > To: Mingw-w64-public > From: Kai Tietz > > A cast via union looks like this: > > type1 *foo(const type1 *my_const_ptr) > > { > > union { > > type1 *t1; > > const type1 *ct1; > > } v; > > v.ct1 = my_const_ptr; > > return v.t1; > > } > > > > The advantage of such a pattern is that no type conversion > > errors/warnings are shown. So for casting from const to none-const, > > this variant is to be preferred. (and it works for C, and C++!!!) > > > > Cheers, > > Kai > > > > 2017-04-05 15:51 GMT+02:00 Mateusz Mikuła : > >>> Hmm, using here "wchar_t *" as cast looks wrong. Actually we should > >>> use anyway PUWSTR_C instead. > >> I noticed it a bit too late and sent another patch casting to PUWSTR_C. > >>> Nevertheless we can have here a const/none-const conversion (means > >>> const specifiers for C-runtime function isn't regarded right?). I > >>> would suggest to introduce a union-cast instead to avoid further > >>> warnings instead. > >> Conversion from const pointer to normal pointer is definitely unsafe but > >> that's probably what GCC just did. > >> I'm unsure what you mean by "union-cast" but you can commit your fix. > >> > >> > >> > -- > >> Check out the vibrant tech community on one of the world's most > >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot > >> ___ > >> Mingw-w64-public mailing list > >> Mingw-w64-public@lists.sourceforge.net > >> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public > >> > > > -- > > Check out the vibrant tech community on one of the world's most > > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > > ___ > > Mingw-w64-public mailing list > > Mingw-w64-public@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/mingw-w64-public > > > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > ___ > Mingw-w64-public mailing list > Mingw-w64-public@lists.sourceforge.net >
Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *
Anything to improve? From 05bc4cbc93f5f9942fc28a578dc1afa68d69daa2 Mon Sep 17 00:00:00 2001 From: Mateusz MikulaDate: Sun, 4 Jun 2017 11:33:22 +0200 Subject: [PATCH] cast ua_wcschr and ua_wcsrchr returns when WSTR_ALIGNED is true Clang doesn't allow implicit conversion form "const wchar_t *" to "PUWSTR_C" (aka wchar_t *) Signed-off-by: Mateusz Mikula --- mingw-w64-headers/include/stralign.h | 15 +-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mingw-w64-headers/include/stralign.h b/mingw-w64-headers/include/stralign.h index 9b5637d6..4b157c27 100644 --- a/mingw-w64-headers/include/stralign.h +++ b/mingw-w64-headers/include/stralign.h @@ -117,12 +117,23 @@ extern "C" { size_t ua_wcslen(PCUWSTR String); #ifndef __CRT__NO_INLINE +union { + wchar_t *wcharPointer; + const wchar_t *constWcharPointer; +} cast; + __CRT_INLINE PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character) { -if(WSTR_ALIGNED(String)) return wcschr((PCWSTR)String,Character); +if(WSTR_ALIGNED(String)) { + cast.constWcharPointer = wcschr((PCWSTR)String,Character); + return cast.wcharPointer; +} return (PUWSTR_C)uaw_wcschr(String,Character); } __CRT_INLINE PUWSTR_C ua_wcsrchr(PCUWSTR String,WCHAR Character) { -if(WSTR_ALIGNED(String)) return wcsrchr((PCWSTR)String,Character); +if(WSTR_ALIGNED(String)) { + cast.constWcharPointer = wcsrchr((PCWSTR)String,Character); + return cast.wcharPointer; +} return (PUWSTR_C)uaw_wcsrchr(String,Character); } #if defined(__cplusplus) && defined(_WConst_Return) -- 2.12.1 -- Original Message -- Subject: Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t * Date: Thu, 6 Apr 2017 11:48:24 +0200 To: Mingw-w64-public From: Kai Tietz > A cast via union looks like this: > type1 *foo(const type1 *my_const_ptr) > { > union { > type1 *t1; > const type1 *ct1; > } v; > v.ct1 = my_const_ptr; > return v.t1; > } > > The advantage of such a pattern is that no type conversion > errors/warnings are shown. So for casting from const to none-const, > this variant is to be preferred. (and it works for C, and C++!!!) > > Cheers, > Kai > > 2017-04-05 15:51 GMT+02:00 Mateusz Mikuła : >>> Hmm, using here "wchar_t *" as cast looks wrong. Actually we should >>> use anyway PUWSTR_C instead. >> I noticed it a bit too late and sent another patch casting to PUWSTR_C. >>> Nevertheless we can have here a const/none-const conversion (means >>> const specifiers for C-runtime function isn't regarded right?). I >>> would suggest to introduce a union-cast instead to avoid further >>> warnings instead. >> Conversion from const pointer to normal pointer is definitely unsafe but >> that's probably what GCC just did. >> I'm unsure what you mean by "union-cast" but you can commit your fix. >> >> >> -- >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> ___ >> Mingw-w64-public mailing list >> Mingw-w64-public@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public >> > -- > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > ___ > Mingw-w64-public mailing list > Mingw-w64-public@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mingw-w64-public From 05bc4cbc93f5f9942fc28a578dc1afa68d69daa2 Mon Sep 17 00:00:00 2001 From: Mateusz Mikula Date: Sun, 4 Jun 2017 11:33:22 +0200 Subject: [PATCH] cast ua_wcschr and ua_wcsrchr returns when WSTR_ALIGNED is true Clang doesn't allow implicit conversion form "const wchar_t *" to "PUWSTR_C" (aka wchar_t *) Signed-off-by: Mateusz Mikula --- mingw-w64-headers/include/stralign.h | 15 +-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mingw-w64-headers/include/stralign.h b/mingw-w64-headers/include/stralign.h index 9b5637d6..4b157c27 100644 --- a/mingw-w64-headers/include/stralign.h +++ b/mingw-w64-headers/include/stralign.h @@ -117,12 +117,23 @@ extern "C" { size_t ua_wcslen(PCUWSTR String); #ifndef __CRT__NO_INLINE +union { + wchar_t *wcharPointer; + const wchar_t *constWcharPointer; +} cast; + __CRT_INLINE PUWSTR_C ua_wcschr(PCUWSTR String,WCHAR Character) { -if(WSTR_ALIGNED(String)) return wcschr((PCWSTR)String,Character); +if(WSTR_ALIGNED(String)) { + cast.constWcharPointer = wcschr((PCWSTR)String,Character); + return cast.wcharPointer; +} return (PUWSTR_C)uaw_wcschr(String,Character); } __CRT_INLINE
[Mingw-w64-public] implicit-fallthrough GCC warning as error in gendef/genpeimg
Hi, GCC 7.1 warns on implicit fallthrough in switch-case. Adding attributes or comments silences this warning. See https://sourceforge.net/p/mingw-w64/bugs/616/ Attached patch solves this for gendef and genpeimg. Please apply if OK. Ruben diff --git a/mingw-w64-tools/gendef/src/gendef.c b/mingw-w64-tools/gendef/src/gendef.c index a935abfe..cefdd8cb 100644 --- a/mingw-w64-tools/gendef/src/gendef.c +++ b/mingw-w64-tools/gendef/src/gendef.c @@ -1031,13 +1031,16 @@ redo_switch: PRDEBUG(" 0x%x illegal ", (unsigned int) b); #endif *aCode=c_ill; return 0; - case c_4: sz++; - case c_3: sz++; - case c_lb: - case c_2: sz++; - case c_retn: case c_retf: - case c_iret: case c_int3: - case c_ad: case c_op: + case c_4: sz++; // fallthrough + case c_3: sz++; // fallthrough + case c_lb: // fallthrough + case c_2: sz++; // fallthrough + case c_retn: // fallthrough + case c_retf: // fallthrough + case c_iret: // fallthrough + case c_int3: // fallthrough + case c_ad: // fallthrough + case c_op: // fallthrough case c_1: *aCode=tb1; return sz; case c_lv: if (oper_mode) sz+=4; diff --git a/mingw-w64-tools/genpeimg/src/genpeimg.c b/mingw-w64-tools/genpeimg/src/genpeimg.c index b2430bbc..6a37b1a0 100644 --- a/mingw-w64-tools/genpeimg/src/genpeimg.c +++ b/mingw-w64-tools/genpeimg/src/genpeimg.c @@ -203,7 +203,7 @@ pass_args (int argc, char **argv) goto error_point; case 'h': if (h[2] == 0) - show_usage (); + show_usage (); // fallthrough default: error_point: fprintf (stderr, "Unknown option ,%s'\n", h); -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public