Compiler "Warnings"

This is a discussion on Compiler "Warnings" within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Seriously whats up with compiler warnings? Warnings don't mean program failure, speciffically in this case my program works exactly as ...

  1. #1
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704

    Compiler "Warnings"

    Seriously whats up with compiler warnings? Warnings don't mean program failure, speciffically in this case my program works exactly as intended - beautifully I might add, but compiles with a healthy list of warnings.


    As far as I've been concerned I've always considered compile warnings to be like "Hey, if you don't know what you're doing this could **** you up.." Of course I've always known what I was doing so I found them to be rediculous nagging.

    So I am asking you, if you compile your programs, works exactly as intended, passes test cases out the wazoo, do you continue to modify the code eliminating "Warnings" ?



    If you are curious, this is the list of warnings from my latest program. I'm not asking for help, I'm just asking for personal opinions.
    C:\MINGW32\bin>gcc -o main.c main.exe
    gcc: main.exe: No such file or directory
    gcc: No input files

    C:\MINGW32\bin>gcc -o main.exe main.c
    main.c:45: warning: data definition has no type or storage class
    main.c: In function `bTreeInit':
    main.c:108: warning: assignment from incompatible pointer type
    main.c:109: warning: assignment from incompatible pointer type
    main.c: In function `bTreeAdd':
    main.c:129: warning: passing arg 1 of `bTreeAdd' from incompatible pointer type
    main.c:131: warning: passing arg 1 of `bTreeAdd' from incompatible pointer type
    main.c: In function `bTreeSearch':
    main.c:146: warning: passing arg 1 of `strlwr' discards `const' from pointer tar
    get type
    main.c:146: warning: passing arg 1 of `strcpy' discards `const' from pointer tar
    get type
    main.c:152: warning: passing arg 1 of `bTreeSearch' from incompatible pointer ty
    pe
    main.c:154: warning: passing arg 1 of `bTreeSearch' from incompatible pointer ty
    pe
    main.c: In function `bTreePreOrder':
    main.c:162: warning: passing arg 1 of `bTreePreOrder' from incompatible pointer
    type
    main.c:163: warning: passing arg 1 of `bTreePreOrder' from incompatible pointer
    type
    main.c: In function `bTreeDepth':
    main.c:174: warning: passing arg 1 of `bTreeDepth' from incompatible pointer typ
    e
    main.c:175: warning: passing arg 1 of `bTreeDepth' from incompatible pointer typ
    e
    main.c: In function `bTreeWordCount':
    main.c:191: warning: passing arg 1 of `bTreeWordCount' from incompatible pointer
    type
    main.c:192: warning: passing arg 1 of `bTreeWordCount' from incompatible pointer
    type
    main.c: In function `bTreePreOrderPop':
    main.c:214: warning: return from incompatible pointer type
    main.c:216: warning: passing arg 1 of `bTreePreOrderPop' from incompatible point
    er type
    main.c:218: warning: assignment from incompatible pointer type
    main.c:219: warning: return from incompatible pointer type
    main.c:219: warning: function returns address of local variable
    main.c:222: warning: passing arg 1 of `bTreePreOrderPop' from incompatible point
    er type
    main.c:224: warning: assignment from incompatible pointer type
    main.c:225: warning: return from incompatible pointer type
    main.c:225: warning: function returns address of local variable
    main.c:231: warning: return from incompatible pointer type
    main.c:231: warning: function returns address of local variable
    main.c: In function `sDocumentAdd':
    main.c:247: warning: passing arg 1 of `sDocumentAdd' from incompatible pointer t
    ype
    main.c: In function `sDocumentInit':
    main.c:251: warning: assignment from incompatible pointer type
    main.c: In function `sDocumentPrint':
    main.c:272: warning: passing arg 1 of `sDocumentPrint' from incompatible pointer
    type
    main.c: In function `queryFile':
    main.c:411: warning: assignment from incompatible pointer type
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  2. #2
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    those warnings could cause memory problems... leaks, miss-assignments, etc. Something you probably dont see while doing tests on the program.
    Hmm

  3. #3
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Yeah. Those kinds of warnings make programs like Windows come to pass.

    [/WindowsBash]

  4. #4
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Both of you were probably right.

    Those warnings were actually pretty serious. And I've completely eliminated them.

    How ever, some warnings are just superflous.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    not really... the way I see it, you should try to minimize warnings by as much as possible... when I'm getting a warning, I find out what it means and if/how I can get rid of it. the standards were drawn up for a reason--there are reasons for every one of the warnings you get. it's not like they just said "let's throw this warning in there just for kicks".

    I agree--you can compile and run a program with no problems if you don't explicitly cast a float to an integer, but that doesn't help the readability of the code, and it may actually remind you that you're going to be losing data there...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    So I am asking you, if you compile your programs, works exactly as intended, passes test cases out the wazoo, do you continue to modify the code eliminating "Warnings" ?
    None of our programs at work is considered complete if there are still warnings in the release build.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    > gcc -o main.c main.exe
    OMG!!!
    So you want to OVERWRITE your source file with the compiled code?
    Be more careful with your commands man, otherwise you'll be in the same position as another poor sap who managed to trash all his code a couple of hours before the "deadline".

    It's a good job the command line was invalid as well, otherwise you'd be scrabbling round for a backup (you do have backups right?)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    The superflous warnings you're talking about are probably like "unsigned being compared against signed value" or "float to int conversion, possible loss of data." For most pieces of data they won't matter, but they could come to bite you in the arse.

  9. #9
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    The most superfluous warnings I've received were from Visual Studio 6.0 telling me that I had identifiers that were too long. I wasn't personally using 300-character identifiers. The problem is that a vector of strings expands out to an identifier of obscene length explictly stating the type of character set being used and the allocator that the vector is using and so on. Eleven warnings every compile like that, but not a single problem caused by it in testing, so meh.

    By the way, has anyone else ever run into that problem?

  10. #10
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    I know a buddy who swears by long and descriptive function/variable names. He'd come up with something like
    Code:
    TakeTheXValueAndCalculateTheCorrectYValue(int thisIsTheXThatIsUsedToComputeTheY)
    <dramatization>
    I'm going to poke fun at him now with this, thanks joshdick.

    Some of you fellas/ladies may have already seen this, but it's always worth a second look.
    http://www.effect.net.au/lukastan/hu...ssages-Mac.htm

  11. #11
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Quote Originally Posted by joshdick
    By the way, has anyone else ever run into that problem?
    Yup, I hated it. It could get pretty bad, especially if you nested your vector of strings even further into STL containers. VS.Net is much nicer about that.

    The warning I'm working on eliminating right now at work involves the STL containers not having dll-interfaces. I don't think it's a problem, but it'd be nice not have 22 warnings every build.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  12. #12
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Quote Originally Posted by pianorain
    I don't think it's a problem, but it'd be nice not have 22 warnings every build.
    Yeah, that's how I felt. I knew there wasn't another truly wrong with my code, but I was concerned about what my boss would think when I sent him my finished product and it gave 11 compiler warnings.

  13. #13
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Quote Originally Posted by Salem
    > gcc -o main.c main.exe
    OMG!!!
    So you want to OVERWRITE your source file with the compiled code?
    Be more careful with your commands man, otherwise you'll be in the same position as another poor sap who managed to trash all his code a couple of hours before the "deadline".

    It's a good job the command line was invalid as well, otherwise you'd be scrabbling round for a backup (you do have backups right?)

    I use MSVC++. I copied this from some one who compiled my program with gcc for me to find out if there would be more/less warnings depending on compiler.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  14. #14
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Jeremy G
    I use MSVC++. I copied this from some one who compiled my program with gcc for me to find out if there would be more/less warnings depending on compiler.
    he didn't use -Wall either
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  15. #15
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    WARNING: The following advice could be devastating in the hands of even a moderate coder. I must stress that 99.9% of warnings are valid and are possible sources of trouble. /WARNING

    You could always use the warning specifier to remove specific undesirable warnings. I prefer to enable my compilers "warnings as errors" option, but should you be an experienced programmer you may safely be able to use the warning specifier.

    #pragma warning ( disable, 4244 )

    which would disable the "conversion from float to int, possible loss of data" warning.

    Or even better: You can push and pop the warning state around the code that generates undesired warnings, and udjust the warning settings solely for that code or file. Check it out.

    Peace
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 05:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM

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