473,395 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Isn't this assignment safe?

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
Jul 22 '05 #1
1 1075
William Payne wrote:
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.
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Rick N. Backer | last post by:
I have an abstract base class that has char* members. Is an assignment operator necessary for this abstract base class? Why or why not? Thanks in advance. Ken Wilson Amer. Dlx. Tele,...
6
by: Josh Mcfarlane | last post by:
Ok, this may be a simple question. I have a base class, CDatabase. This class contains pointers to other classes containing data from raw files. Due to the way our system is set up, the format...
21
by: Ike Naar | last post by:
Consider the following code: #include <stdlib.h> struct s { /* ... */ struct s * next; };
34
by: Chris | last post by:
Is there ever a reason to declare this as if(*this == rhs) as opposed to what I normally see if(this == &rhs) ?
5
by: Hallvard B Furuseth | last post by:
Does struct assignment copy padding bytes? Some compilers do, but I couldn't find anything in the standard which says they must. What I need is for any padding bytes to contan initialized values...
5
by: Weihui Shen | last post by:
Hello. Sometimes I see that some class constructors were implemented with assignment operator and I wanna know whether it is safe to do that or not?
61
by: warint | last post by:
My lecturer gave us an assignment. He has a very "mature" way of teaching in that he doesn't care whether people show up, whether they do the assignments, or whether they copy other people's work....
12
by: hweekuan | last post by:
hi, it seems i can't assign the const variable u in class A, one way to solve the problem may be to build a copy constructor. however, why does C++ or vector class not like this code? my g++ is:...
4
by: George2 | last post by:
Hello everyone, The following swap technique is used to make assignment operator exception safe (means even if there is exception, the current object instance's state is invariant). It used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.