|
|
commit 2b29e921db8800b015fe9f9d664e506c3e02b0e5
Author: Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Tue Aug 31 16:52:54 2021 +0200
Commit: Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Tue Aug 31 16:52:54 2021 +0200
Fix MSVC compiler warnings in test/icon.cxx (#109)
Also:
- remove unnecessary 'size_t' conversions from FL/fl_casts.H
- add reverse conversions from integer types to 'void *'
FL/fl_casts.H | 28 ++++++++++++----------------
test/icon.cxx | 10 +++++-----
2 files changed, 17 insertions(+), 21 deletions(-)
diff --git FL/fl_casts.H FL/fl_casts.H
index 965f12e..1d0d881 100644
--- FL/fl_casts.H
+++ FL/fl_casts.H
@@ -17,22 +17,18 @@
#include <FL/platform_types.h>
-inline char fl_char(void *v) { return (char)(fl_intptr_t)v; }
-inline int fl_int(void *v) { return (int)(fl_intptr_t)v; }
-inline long fl_long(void *v) { return (long)(fl_intptr_t)v; }
+inline char fl_char(void *v) { return (char)(fl_intptr_t)v; }
+inline int fl_int(void *v) { return (int)(fl_intptr_t)v; }
+inline long fl_long(void *v) { return (long)(fl_intptr_t)v; }
-inline unsigned char fl_uchar(void *v) { return (unsigned char)(fl_uintptr_t)v; }
-inline unsigned int fl_uint(void *v) { return (unsigned int)(fl_uintptr_t)v; }
-inline unsigned long fl_ulong(void *v) { return (unsigned long)(fl_uintptr_t)v; }
+inline unsigned char fl_uchar(void *v) { return (unsigned char)(fl_uintptr_t)v; }
+inline unsigned int fl_uint(void *v) { return (unsigned int)(fl_uintptr_t)v; }
+inline unsigned long fl_ulong(void *v) { return (unsigned long)(fl_uintptr_t)v; }
-#if 0 /* not necessary */
+// the following conversions can be used to silence MSVC warning C4312:
+// 'type cast': conversion from '<type>' to 'void *' of greater size
-inline char fl_char(size_t v) { return (char)v; }
-inline int fl_int(size_t v) { return (int)v; }
-inline long fl_long(size_t v) { return (long)v; }
-
-inline unsigned char fl_uchar(size_t v) { return (unsigned char)v; }
-inline unsigned int fl_uint(size_t v) { return (unsigned int)v; }
-inline unsigned long fl_ulong(size_t v) { return (unsigned long)v; }
-
-#endif /* not necessary */
+inline void *fl_voidptr(int v) { return (void *)(fl_intptr_t)v; }
+inline void *fl_voidptr(unsigned int v) { return (void *)(fl_uintptr_t)v; }
+inline void *fl_voidptr(long v) { return (void *)(fl_intptr_t)v; }
+inline void *fl_voidptr(unsigned long v) { return (void *)(fl_uintptr_t)v; }
diff --git test/icon.cxx test/icon.cxx
index c36e9a0..3bf565f 100644
--- test/icon.cxx
+++ test/icon.cxx
@@ -1,7 +1,7 @@
//
// Icon test program for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2010 by Bill Spitzak and others.
+// Copyright 1998-2021 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -22,7 +22,7 @@
static Fl_Double_Window *win;
void choice_cb(Fl_Widget *, void *v) {
- Fl_Color c = (Fl_Color)(fl_intptr_t)v;
+ Fl_Color c = (Fl_Color)fl_uint(v);
uchar buffer[32*32*3];
Fl_RGB_Image icon(buffer, 32, 32, 3);
icon.color_average(c, 0.0);
@@ -30,9 +30,9 @@ void choice_cb(Fl_Widget *, void *v) {
}
Fl_Menu_Item choices[] = {
- {"Red",0,choice_cb,(void*)FL_RED},
- {"Green",0,choice_cb,(void*)FL_GREEN},
- {"Blue",0,choice_cb,(void*)FL_BLUE},
+ {"Red", 0, choice_cb, fl_voidptr(FL_RED)},
+ {"Green", 0, choice_cb, fl_voidptr(FL_GREEN)},
+ {"Blue", 0, choice_cb, fl_voidptr(FL_BLUE)},
{0}
};
[ Direct Link to Message ] | |
|
| |