warning C4838: conversion from 'unsigned int' to 'FLAGS' requires a narrowing conversion

SDK supports Prepar3D’s philosophy of an open development architecture and encourages third parties to bring new innovations with improved add-ons and training content.
Locked
User avatar
DaiG
Posts: 321
Joined: Fri Jun 16, 2017 11:27 am
Location: The Kingdom of Mourne

warning C4838: conversion from 'unsigned int' to 'FLAGS' requires a narrowing conversion

Post by DaiG »

Got me scratching my head, this one. The error occurs only with the VS2015 - on the VS2015 menu go to

Project | [project] property pages

Under Configuration | General | Platform Toolset

If set to "Visual Studio 2015 (v140)" you'll get the errors: if set to "Visual Studio 2013 (v120)" you don't get the errors. The actual target of the error is the MOUSE stuff and the reference line is always the closing MOUSE_END. My Character Set is 'Use Multi-Byte Character Set' and the Code Generation | Runtime Library is set to 'Multi-threaded Debug (/MTd)'. If compiled with the "Visual Studio 2013 (v120)" toolset (so no errors or warnings) the gauge shows up in FSX but not in P3Dv4 (as expected). Anyone any ideas as to what I've overlooked?
PILOT'S developer
i9-12000KF
64Gb DDR4
RTX3080Ti
Western Digital 2Tb NVMe drive for P3D
m/b Z690 chipset
EllipticCurve
Posts: 151
Joined: Mon Jun 12, 2017 6:14 pm

Re: warning C4838: conversion from 'unsigned int' to 'FLAGS' requires a narrowing conversion

Post by EllipticCurve »

unsigned int on 64-bit is IMPLEMENTATION SPECIFIC, and could be 64-bits wide, or it could be 32-bits wide! How wide is FLAGS under 64-bit?

Dump the return value of sizeof(int) and see what it says.

EDIT: doing a bit more reading, the following code will also produce this error:

Code: Select all

int a[] = { 1.0 };
The reason is type int can't represent all the values of type float, so C4838 will be thrown, even though 1.0 can be exactly represented as an integer!!!

It's times like this where C++ really gets too smart for its own good. What happens in reality with code like this is loss of precision (int and float are both 4 bytes long under MS C++ so there is no possibility to overflow).
All comments and opinions are my own.
Locked