Re: ? Run-Time Check Failure #1 with Built-In RGB Functions

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"Alec S." wrote:
Using smaller-type check option (/RTCc), the line that casts the
COLORREF (ie DWORD) variable to a BYTE throws the following
Run-Time Check Failure #1 even though its an explicit cast:

Run-Time Check Failure #1 - A cast to a smaller data type has
caused a loss of data. If this was intentional, you should mask
the source of the cast with the appropriate bitmask. For
example: char c = (i & 0xFF); Changing the code in this way will
not affect the quality of the resulting optimized code.

I tried following code with VC++2008 SP1:

// RGB.cpp
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdio.h>

int main()
{
COLORREF c=RGB(255,255,255);
BYTE a=GetRValue(c);
BYTE b=GetRValue(RGB(255,255,255));

printf("a=%d, b=%d", a, b);

return 0;
}

This is the command-line session:

C:\VSProjects>cl /RTCc RGB.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

RGB.cpp
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.

/out:RGB.exe
RGB.obj

C:\VSProjects>RGB
a=255, b=255


Could you post a minimal example that triggers the run-time error?

Alex


.



Relevant Pages

  • required hack for Xeon 64
    ... to make in order to avoid the following message: ... Run-Time Check Failure #1 - A cast to a smaller data type has caused a loss ... you should mask the source of the cast ...
    (comp.lang.tcl)
  • Re: [patch 03/41] cpu alloc: Use cpu allocator instead of the builtin modules per cpu allocator
    ... Indenting broke. ... I suspect you'll need to cast it to be able ... Because a cpu_allocfailure is a major catastrophe. ...
    (Linux-Kernel)
  • Re: Enhancing spell skill
    ... more effective, cost less PW to cast, etc.) if all my currently ... Some spells not discussed by others so far in the thread: ... I have both spells and can cast them somewhere ... between 50%-80% failure, ...
    (rec.games.roguelike.nethack)
  • Re: Cast and runtime failure, char c = (i $ 0xff)
    ... But with vc7 i get the runtime check failure dialog box, ... "Cast to smaller datatype bla. ... >> But then the compiler complains about the cast of int to char and i ...
    (microsoft.public.vc.language)