473,406 Members | 2,620 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,406 software developers and data experts.

About possible data lose warning

int main()
{
int aNormalInt = 0;
short aShortInt = 0;
aShortInt = aNormalInt; // Why I am not getting a warining for possible
data lose in MS VC++6.0, even with warning level 4?
return 0;
}

-Vinodh
Jul 22 '05 #1
9 1454
"Vinodh Kumar P" <vi****@here.com> wrote...
int main()
{
int aNormalInt = 0;
short aShortInt = 0;
aShortInt = aNormalInt; // Why I am not getting a warining for possible
data lose in MS VC++6.0, even with warning level 4?
return 0;
}


Could be the compiler sees that you're doing nothing, the program is
essentially

int main()
{
return 0;
}

Ask in microsoft.public.vc.language, they know more about specifics of
the Visual C++ compiler.

V
Jul 22 '05 #2
This should really be in a VC newsgroup.

<OT>However, the warning is signalling that that data in aNormalInt is
truncated in order to fit the aShortInt, so you could lose a few bits
in the process.</OT>

Jul 22 '05 #3
C is more of a user-driven language, one that allows the programmer to do
things they may not be able to do in a more restricting language, like
Java. A Java compiler may warn you about data conversion but most C
compilers will assume you meant to do it, and allow it.

Jul 22 '05 #4
Victor Bazarov wrote:
"Vinodh Kumar P" <vi****@here.com> wrote...

int main()
{
int aNormalInt = 0;
short aShortInt = 0;
aShortInt = aNormalInt; // Why I am not getting a warining for possible
data lose in MS VC++6.0, even with warning level 4?
return 0;
}


Could be the compiler sees that you're doing nothing, the program is
essentially

int main()
{
return 0;
}

Compiler is not giving warning because the above code is semantically valid.
Semantic error has nothing to do with the optimization. Read section
4.7 Integral conversions of C++ standard.
"1 An rvalue of an integer type can be converted to an rvalue of another
integer type. An rvalue of an enumeration type can be converted to an
rvalue of an integer type."

You will get similar 'verse' from c89/c99 standard.

Krishanu
Jul 22 '05 #5
Krishanu Debnath wrote:
Victor Bazarov wrote:

"Vinodh Kumar P" <vi****@here.com> wrote...
int main()
{
int aNormalInt = 0;
short aShortInt = 0;
aShortInt = aNormalInt; // Why I am not getting a warining for possible
data lose in MS VC++6.0, even with warning level 4?
return 0;
}


Could be the compiler sees that you're doing nothing, the program is
essentially

int main()
{
return 0;
}


Compiler is not giving warning because the above code is semantically valid.
Semantic error has nothing to do with the optimization. Read section
4.7 Integral conversions of C++ standard.
"1 An rvalue of an integer type can be converted to an rvalue of another
integer type. An rvalue of an enumeration type can be converted to an
rvalue of an integer type."

You will get similar 'verse' from c89/c99 standard.


There is no way to explain a particular compiler's behaviour by quoting
the Standard, especially when warnings are concerned. Warnings (and
a great multitude of them) are often not required but still emitted by
all compilers in one situation or another.

V
Jul 22 '05 #6
Razzer wrote:
This should really be in a VC newsgroup.

<OT>However, the warning is signalling that that data in aNormalInt is
truncated in order to fit the aShortInt, so you could lose a few bits
in the process.</OT>


Yes, such warning _would_ be signaling, and that's what the OP was
asking about. The OP was concerned that _no_warning_ was issued (reread
the original post).
Jul 22 '05 #7
>(reread
the original post).

Whoops. I can't read very well, I guess.

Jul 22 '05 #8
Vinodh Kumar P wrote:
aShortInt = aNormalInt; // Why I am not getting a warining for
possible
data lose in MS VC++6.0, even with warning level 4?


.... because, as I remember, on VC6

sizeof(aShortInt)
== sizeof(aNormalInt)
== sizeof(aLongInt)
== 4.

All 32-bit...

Greetings,

Thomas Ritter
Jul 22 '05 #9
Thomas Ritter wrote:
Vinodh Kumar P wrote:
aShortInt = aNormalInt; // Why I am not getting a warining for
possible
data lose in MS VC++6.0, even with warning level 4?

... because, as I remember, on VC6

sizeof(aShortInt)
== sizeof(aNormalInt)
== sizeof(aLongInt)
== 4.

All 32-bit...


You remember incorrectly. sizeof(short) is 2 in VC++ v6.

V
Jul 22 '05 #10

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

Similar topics

14
by: Matt | last post by:
Any progammers looking for a killer app to develop? How about a voice enabled forum? One of the most powerful, exciting, and engrossing experiences on the Internet is the Forum. The first great...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Eric Lilja | last post by:
Hello, I have a few global variables in my program. One of them holds the name of the application and it's defined in a header file globals.hpp (and the point of definition also happen to be the...
5
by: My4 | last post by:
Dear Sirs, I want to give the user of my intranet a warning that if he uses the explorers right corner 'X' to close the browser he looses his information. I tried to prevent him from closing, or...
28
by: Lee Rouse | last post by:
Hello all, This is going to be a rather lengthy "question". I have an Access 2k database, separated front end/back end. Front end copies are on about 30 workstations and used frequently during...
19
by: Clint Olsen | last post by:
I was just thinking about the virtues of C vs. C++ wrt. ADT/generic programming. The biggest complaint about writing container libraries for ADTs is that void * offers no type safety. Does it...
2
by: teo | last post by:
I need to use the 'Session_End' event in the 'Global.asax' file. It only works if in the 'Web.config' file the 'sessionState mode' Tag is present and its value is set to "InProc" 1) I...
13
by: lane straatman | last post by:
I'm trying to figure out what data type is appropriate to represent a card in a game. The idea that I thought was going to work was a struct, foo, with two integer fields and two fields of char...
5
by: FP | last post by:
Hi, i'm currently developing a class to communicate with a serial device,using the SerialPort component. Basically,the main application will interact with this class through its method "Call",the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.