Board index » cppbuilder » bad C++ Warning on BDS2006

bad C++ Warning on BDS2006


2006-11-15 04:01:11 PM
cppbuilder84
Hi to all,
when I compile my program in Release mode I obtain
always a wrong compiler Warning which I don't understand:
// process colors and dithering
if (FPalette != NULL && FPalette->ColorCount != 0)
{
Graphics::TBitmap* Bitmap = new Graphics::TBitmap;
Bitmap = ReduceColors
(
FImage->Bitmap,
rmPalette,
TDitherMode(ImageInfo->DitheringMode),
Ceil(Log10(FPalette->ColorCount) / Log10(2)),
FPalette->HPalette
);
ConvertBitmapTo24BPP(Bitmap);
FImage->Bitmap->Assign(Bitmap);
delete Bitmap;
}
[C++ Warning] ImageMan.cpp(536): W8004 'Bitmap' is assigned a value that is
never used
What's happend ?
Can you suggest me something about ?
Thank you very much...
--
Silverio, SiD Vicenza - Italy
Yahoo Messanger: SiDorDiS
 
 

Re:bad C++ Warning on BDS2006

SD wrote:
Quote
Hi to all,
when I compile my program in Release mode I obtain
always a wrong compiler Warning which I don't understand:

// process colors and dithering
if (FPalette != NULL && FPalette->ColorCount != 0)
{
Graphics::TBitmap* Bitmap = new Graphics::TBitmap;
Bitmap = ReduceColors
(
FImage->Bitmap,
rmPalette,
TDitherMode(ImageInfo->DitheringMode),
Ceil(Log10(FPalette->ColorCount) / Log10(2)),
FPalette->HPalette
);
ConvertBitmapTo24BPP(Bitmap);
FImage->Bitmap->Assign(Bitmap);
delete Bitmap;
}

[C++ Warning] ImageMan.cpp(536): W8004 'Bitmap' is assigned a value that is
never used

What's happend ?
Well, it's perfectly expected, you set the value of the Bitmap variable
twice, so the first value is never used and leaked.
Quote
Can you suggest me something about ?
Learn to read? <vbg>
 

Re:bad C++ Warning on BDS2006

"SD" < XXXX@XXXXX.COM >wrote in message
Quote
when I compile my program in Release mode I obtain
always a wrong compiler Warning which I don't understand:
It is not a wrong warning. It is a valid and accurate warning. You really
are assigning a value to your Bitmap variable that is not being used
anywhere. And in fact, the warning is pointing out a bug in your code.
Quote
Graphics::TBitmap* Bitmap = new Graphics::TBitmap;
Bitmap = ReduceColors
<snip>
You are allocating a new TBitmap object, but then immediately re-assigning
the variable to point at a different object. So you get the warning for the
first object that you never use, and you are leaking the memory for that
object since you cannot free it properly.
Get rid of the 'new' statement altogether:
Graphics::TBitmap* Bitmap = ReduceColors(...);
Gambit
 

{smallsort}

Re:bad C++ Warning on BDS2006

"Remy Lebeau (TeamB)" wrote:
Quote
It is not a wrong warning. It is a valid and accurate warning. You
really
are assigning a value to your Bitmap variable that is not being used
anywhere. And in fact, the warning is pointing out a bug in your code.

>Graphics::TBitmap* Bitmap = new Graphics::TBitmap;
>Bitmap = ReduceColors
<snip>

You are allocating a new TBitmap object, but then immediately re-assigning
the variable to point at a different object. So you get the warning for
the
first object that you never use, and you are leaking the memory for that
object since you cannot free it properly.

Get rid of the 'new' statement altogether:

Graphics::TBitmap* Bitmap = ReduceColors(...);
Oh my g.d, I feel me very studip now ;(
Thanks for solving my problem...
:)