Isn't this assignment safe?

W

William Payne

Hello! I realise questions about compilers are considered off-topic here but
I still would like to know if the following statement is considered safe. My
compiler warns about it (see below).

the statement:
long size = type == TYPE_FOLDER ? -1 : find_data.nFileSizeLow / 1024;

the warning:
main_window_procedure.cpp:129: warning: converting of negative value
`-0x0000000
01' to `long unsigned int'

type is an instance of:
enum Type
{
TYPE_FILE,
TYPE_FOLDER
};

find_data.nFileSizeLow is of type unsigned long

I am using GCC 3.4.0.

I don't understand that warning at all...the only problem I can see is if
the result of find_data.nFileSizeLow / 1024 is too big to fit in a long, but
the warning doesn't seem to be about that, or? (As a side note, I am not too
worried that the long will overflow in real-world use). I always like to
compile my code with warning level cranked up to max then I try to get rid
of most of warnings or at least understand them.

Thanks for any replies

/ WP
 
B

Bill Seurer

William said:
I don't understand that warning at all

I think what is happening is that the whole ?: expression is being typed
as "long unsigned int" so the -1 is being converted to that and thus the
warning. Try forcing the "find_data.nFileSizeLow / 1024" part to be long.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,901
Members
47,442
Latest member
KevinLocki

Latest Threads

Top