those damn warnings!!!

This is a discussion on those damn warnings!!! within the C++ Programming forums, part of the General Programming Boards category; ( I'm using Visual Studio 2003 .NET ) In all of my programs i get thousand's of this warnings ( ...

  1. #1
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377

    those damn warnings!!!

    ( I'm using Visual Studio 2003 .NET )
    In all of my programs i get thousand's of this warnings ( in my Task List )

    : warning C4244: 'argument' : conversion from 'double' to 'int', possible loss of data

    and they ........ me off!
    How can i get rid of them???
    For example i got an int a, a have to assign a new value for example 8/7.
    I let it go like this, my a = 1, but i get a warning. Is there a possible way to fix this???

    And is it Ok to leave a program with so many warnings?
    If it's ok just tell me the way to turn their display off.
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    those warnings appear for good reason -- the way to get rid of them is to correct your code. Many (most) warnings that appear in YOUR code are really errors and should be treated as such.

    you can also use #pragma to turn off specific warnings. Put this before any includes except stdafx.h

    Code:
    #pragma warning(disable: 4244)

  3. #3
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    So tell me how can i fix the above example.
    Is there alternative???
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    you could cast to the right type like
    Code:
    double a = 7.0;
    int b = 2;
    int res = (int)(a/b);
    or better
    Code:
    int res = static_cast<int>(a/b);
    If you really want to convert a double to an int.
    Kurt

  5. #5
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Allright thats cool. But writing all those (int) is really boring...
    But can this little warning do anything serius.
    Anyway the type is converted automaticly.
    And i do Fix every warning that isn't conversion related!
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    For example i got an int a, a have to assign a new value for example 8/7.
    I let it go like this, my a = 1, but i get a warning. Is there a possible way to fix this???
    Yeah, when you're going to chop off the decimal part of the number, which is what happens when you assign a fraction to an int variable, tell the compiler and everyone that reads your code that you really intended for that to happen:
    Code:
    int a = static_cast<int>(8/7);

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > How can i get rid of them???
    Well if you have so many, then it seems to me you just threw the code together without any regard as to whether you chose the correct types for things. Carefully chosen types will tell you a lot more when you start to do dumb things like add apples to oranges, which would otherwise go un-noticed until much later.

    Or you were using a less fussy compiler and now you're only just discovering the results of your sloppy coding practices.

    It's one of the hazards of learning the compiler as opposed to learning the language. Change your compiler and you have to start all over again. Sooner or later, most people realise this approach sucks and they try and learn the language first.

    > and they ........ me off!
    And we have a phrase "a poor workman blames his tools".

  8. #8
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Quote Originally Posted by Ancient Dragon
    Code:
    #pragma warning(disable: 4244)
    That helped, Thanks!
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by ElastoManiac
    And i do Fix every warning that isn't conversion related!
    yes, you should make every effort to correct the problem(s). If you don't most of them will probably cause serious runtime errors.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Quote Originally Posted by Ancient Dragon
    you can also use #pragma to turn off specific warnings. Put this before any includes except stdafx.h

    Code:
    #pragma warning(disable: 4244)
    That's probably only for MSVC, although I don't know for sure.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by dwks
    That's probably only for MSVC, although I don't know for sure.
    Probably -- but that is the compiler he is using.

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Yes, I know, but [s]he's not the only one reading this thread.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #13
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advice on removing valid (but minor) compiler warnings
    By PaulBlay in forum C Programming
    Replies: 12
    Last Post: 04-20-2009, 12:16 PM
  2. Warnings when using vector of vector
    By Boksha in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2008, 01:54 PM
  3. Compilers and warnings
    By rogster001 in forum C Programming
    Replies: 6
    Last Post: 03-26-2008, 05:16 AM
  4. Replies: 9
    Last Post: 03-14-2008, 09:55 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21