C Board  

Go Back   C Board > Community Boards > General Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 04-17-2005, 07:46 PM   #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.
Quote:
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.)
Jeremy G is offline   Reply With Quote
Old 04-17-2005, 08:06 PM   #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
B0bDole is offline   Reply With Quote
Old 04-17-2005, 08:33 PM   #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]
gcn_zelda is offline   Reply With Quote
Old 04-17-2005, 08:52 PM   #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.)
Jeremy G is offline   Reply With Quote
Old 04-18-2005, 01:00 AM   #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
major_small is offline   Reply With Quote
Old 04-18-2005, 02:18 AM   #6
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,767
Quote:
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.
nvoigt is offline   Reply With Quote
Old 04-18-2005, 10:56 AM   #7
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,630
> 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.

Salem is offline   Reply With Quote
Old 04-18-2005, 12:50 PM   #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.
skorman00 is offline   Reply With Quote
Old 04-18-2005, 01:01 PM   #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?
joshdick is offline   Reply With Quote
Old 04-18-2005, 01:15 PM   #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
skorman00 is offline   Reply With Quote
Old 04-18-2005, 01:26 PM   #11
Anti-Poster
 
Join Date: Feb 2002
Posts: 1,223
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.
__________________
Rule #1: Every rule has exceptions
pianorain is offline   Reply With Quote
Old 04-18-2005, 01:36 PM   #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.
joshdick is offline   Reply With Quote
Old 04-18-2005, 01:52 PM   #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.)
Jeremy G is offline   Reply With Quote
Old 04-18-2005, 07:50 PM   #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
major_small is offline   Reply With Quote
Old 04-19-2005, 12:53 AM   #15
Peace
 
Join Date: Aug 2001
Posts: 1,512
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)
lightatdawn is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
added start menu crashes game avgprogamerjoe Game Programming 6 08-29-2007 01:30 PM
Compiler Paths... Cobra C++ Programming 5 09-26-2006 04:04 AM
C Compiler and stuff pal1ndr0me C Programming 10 07-21-2006 11:07 AM
I can't get this new compiler to work. Loduwijk C++ Programming 7 03-29-2006 06:42 AM
how to call a compiler? castlelight C Programming 3 11-22-2005 11:28 AM


All times are GMT -6. The time now is 09:54 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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