Re: C4244 Warning with +=

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Many thanks for the links. I guess that answers my question although i think
i'd still argue that when the types are the same there should be no warning,
after all it's perfectly possible for the ++ or -- operators to overflow but
you don't get warnings about that.

Matt

"Igor Tandetnik" wrote:

> Matt <Matt@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> > I'm compiling my code with warning level 4 and i am getting C4244
> > warnings: conversion from 'int' to 'unsigned short', possible loss of
> > data on code like this:
> >
> > WORD w1 = 5;
> > WORD w2 = 2;
> >
> > w1 += w2; // <--- generates warning
> >
> > Both types match - how can i get rid of this warning?
>
> This was discussed at some length, e.g. here
>
> http://groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/95ecc316830c1562/a713ae3345f0c810
> http://groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/d95905585ebf6d7c/71dab3957a027827
>
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>
.



Relevant Pages

  • Re: PROP_DATA_ENTRY displays warning on VT_BSTR
    ... "Igor Tandetnik" wrote: ... > The cause is the use of offsetof macro inside PROP_DATA_ENTRY that ... > This offset is then stored in a DWORD member of a struct. ... > the warning that the conversion may result in loss of data. ...
    (microsoft.public.vc.atl)
  • Re: Question about Deprecated Functions
    ... >> removing functions like strcpy would mean giving up the compatibility ... > As to the reason for the warning, ... > Igor Tandetnik ...
    (microsoft.public.vc.language)
  • Re: deprecated copy
    ... In article, Igor Tandetnik wrote: ... Newsgroups: microsoft.public.vc.language ... doesn't suppress this warning. ...
    (microsoft.public.vc.language)
  • Re: [PATCH] fs/fcntl.c - remove impossible <0 check in do_fcntl - arg is unsigned.
    ... Ok, let me try and argue in favour of it, and if you think the arguments ... with the standard compile options no such warning is given. ... that I am trying to get rid of as many potential warnings as I can - It ...
    (Linux-Kernel)
  • Re: The real issue with accessors and mutators
    ... Can you share at least the chapter number where such warning is? ... They are potentially harmful. ... You cannot argue against it because there are ... there can be instances when driving fast is essential to survival. ...
    (comp.lang.cpp)