-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color struct defines 1 uint
field, and many consts typed as int
#1825
Comments
int
uint
field, and many consts typed as int
typedef DWORD ARGB;
typedef DWORDLONG ARGB64;
class Color
{
// ...
public:
enum
{
AliceBlue = 0xFFF0F8FF,
AntiqueWhite = 0xFFFAEBD7,
Aqua = 0xFF00FFFF,
Aquamarine = 0xFF7FFFD4,
Azure = 0xFFF0FFFF,
Beige = 0xFFF5F5DC,
Bisque = 0xFFFFE4C4,
Black = 0xFF000000,
// ...
}
protected:
ARGB Argb;
// ...
} In Microsoft Visual C++ (MSVC), the default underlying type of an unscoped enumeration is |
Thanks for looking into this, @riverar. I see now why the metadata is the way it is. In C++, signed and unsigned integers tend to be more interchangeable than in C# I believe, so I can see why these headers were sufficient. That said, do you have any concerns with win32metadata adding the necessary overrides to type the constants to match the struct type? That would be enough to enable |
Insisting that these enumerator values are signed, because they technically are, when they were clearly indented to be unsigned and MSVC was happy to treat them either way back in the day is not super helpful, essentially forcing every language to inject a cast and requiring things like the |
Are there any changes outstanding here? |
There’s a current tension between projection authors and users, and projection authors and metadata, due to the stance of metadata on preserving ABI and API. The concerns raised by these positions are not well-documented or demonstrated. For example, we often take firm positions on the handling of unsigned/signed integers in the context of “ABI preservation”. However, there’s no clear evidence that this is ABI significant. On the other hand, it does seem to be important from an “API preservation” perspective. It’s plausible situations involving C++ code generation or maybe static libraries could result in hard-to-identify bugs. I think we might need to improve our messaging on this subject and provide proper documentation. |
If the constants were always used in the |
Why does the GDI+
Color
struct in the metadata define auint
instance field and manyint
constants that would appear to be meant to be assigned to the instance field?I further wonder why these constants are not typed as
Color
themselves, similar to howS_OK
is defined with a value of 0 (the integer) but typed asHRESULT
?Ideally we want the user to be able to type
Color.AliceBlue
and have that represent an instance of theColor
struct initialized to the value inAliceBlue
. But as it is now, the user would have to type:That doesn't quite roll off the tongue, does it?
Aside
Incidentally, another deviation from the pattern I (and CsWin32) are more familiar with is that these struct-value constants are defined as constants of the
Apis
class. But these color constants are defined in the struct itself. That required a fix to CsWin32. The fix was easy enough, but it does mean that someone asking for theColor
struct will immediately get ~148 color constants declared instead of having to request each named color specifically for generation. I'm on the fence on this, but maybe it's best this way so the user can easily select their chosen color from a picklist rather than referring to documentation and then naming the (presumably very few) colors they actually want to use.The text was updated successfully, but these errors were encountered: