Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Yandex, Yahoo!

Members: 0
Guests: 6
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » Compiler missed something?
Forum Rules | Mark all | Recent Posts

Compiler missed something?
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Mar 18, 2006, 9:38 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

So. Here's a mystery for everyone. Why didn't the compiler scream about there being no return value in this?
GCC 4.0.2 on Fedora Core 4.

// This determines the number of sockets to put on a weapon or a body armor
int num_sockets( short level )
{
   short value = 0;

   if( level < ( LEVEL_AVATAR * 0.20 ) )
      value = number_range( 0, 1 );
   else if( level >= ( LEVEL_AVATAR * 0.21 ) && level <= ( LEVEL_AVATAR * 0.50 ) )
      value = number_range( 0, 2 );
   else if( level >= ( LEVEL_AVATAR * 0.51 ) && level <= ( LEVEL_AVATAR * 0.70 ) )
      value = number_range( 1, 2 );
   else if( level >= ( LEVEL_AVATAR * 0.71 ) && level <= ( LEVEL_AVATAR * 0.90 ) )
      value = number_range( 1, 3 );
   else
      value = number_range( 2, 3 );
}
       
Post is unread #2 Mar 19, 2006, 1:03 pm
Go to the top of the page
Go to the bottom of the page

Zeno
Sorcerer
GroupMembers
Posts723
JoinedMar 5, 2005

Weird. This is what I get on gcc 3.3.6:
In function `num_sockets':
warning: control reaches end of non-void function
       
Post is unread #3 Mar 23, 2006, 3:17 pm   Last edited Mar 23, 2006, 3:20 pm by Keberus
Go to the top of the page
Go to the bottom of the page

Keberus
Conjurer
GroupFUSS Project Team
Posts341
JoinedJun 4, 2005

Strange that it didn't. What would be the point of setting value if its not being used?

KeB
       
Post is unread #4 Mar 23, 2006, 4:30 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

That's the mystery I was wondering about which led me to think 4.0.2 has a bug, fortunately I'm in the process now of installing FC5 which has gcc 4.1 so we'll see.
       
Post is unread #5 Mar 23, 2006, 8:41 pm
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

4.1 failed to pick up the error as well. Possible then that C++ under 4.1 is smart enough to know what to return? I can't really see how though.
       
Post is unread #6 Mar 23, 2006, 11:28 pm
Go to the top of the page
Go to the bottom of the page

Conner
Sorcerer
GroupMembers
Posts870
JoinedMay 8, 2005

Could it be a bug that started in 4.0.2 and didn't get caught before 4.1 came out?
       
Post is unread #7 Mar 24, 2006, 7:00 am
Go to the top of the page
Go to the bottom of the page

Tranin

GroupMembers
Posts14
JoinedMar 16, 2006

I don't think its an issue with your compiler, I'm running debian with gcc version 3.3.5, and I did not get a warning about the missing return statement. I don't know a whole lot about the gcc compilers, but I know mine hasn't given me any problems with what I do. This is pretty interesting though!
       
Post is unread #8 Mar 24, 2006, 7:52 am
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,639
JoinedJan 1, 2002

Conner: I suppose it's possible. I haven't been able to reduce a testcase though that they would accept in their bug reporting procedure. But I may submit it anyway. I always got the proper warning on gcc 3.x compilers.

Tranin: That's interesting. 3.3.5 doesn't issue the warning either? It really should be because that function needs to return something to the calling function, and if it doesn't the value at the other end will probably be undefined. Not a good spot to be in if the warning isn't issued.
       
Post is unread #9 Mar 24, 2006, 4:25 pm   Last edited Mar 25, 2006, 10:07 am by Zeno
Go to the top of the page
Go to the bottom of the page

Zeno
Sorcerer
GroupMembers
Posts723
JoinedMar 5, 2005

I asked around.
With the default warning levels no GCC I used ever did that. And I used it since 1.37.2 or .3 (not entirely sure).


And you do have -Wall on right?
       
Pages:<< prev 1 next >>