[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Comparison of Constant....

Comparison of Constant....

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Alyce   (43 posts)  [Biography] bio
Date Thu 08 Sep 2016 02:37 AM (UTC)
Message
This has been bugging me... It's not TOO big an issue I don't believe, but it's one that is causing the compile to not be nice using smaugfuss 1.9 and compiling with cygwin.


comm.c: In function ‘void nanny_get_name(DESCRIPTOR_DATA*, char*)’:
comm.c:1886:44: warning: comparison of constant ‘255’ with boolean expression is always false [-Wbool-compare]
    if( check_playing( d, argument, FALSE ) == BERR )
                                            ^
comm.c:1954:12: warning: comparison of constant ‘255’ with boolean expression is always false [-Wbool-compare]
    if( chk == BERR )
            ^
comm.c: In function ‘void nanny_get_old_password(DESCRIPTOR_DATA*, char*)’:
comm.c:2049:12: warning: comp


I did some research a while back and someone had posted how to change the code to remove those warnings.. and it did.. however when connecting to a link-dead player, it caused segmentation faults, so I just changed it back and haven't really bothered with it since...

Now i'm just about done adding what I wanted to to the code-base and changed it to suit my needs, but that one lingering issue is still bugging me.

Mud works fine with the warnings there.. no segfault on connecting to link-dead... I just want them gone.

has anyone else ran across this issue? if so, how did you resolve it?
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Thu 08 Sep 2016 06:05 PM (UTC)

Amended on Thu 08 Sep 2016 06:10 PM (UTC) by Fiendish

Message
So...

The C language didn't have a native bool type until C99. Before that, people would resort to stupid tricks like you can find in src/mud.h where it says
typedef unsigned char bool;
#define true 1
#define false 0


That means that the check_playing function in src/comms.c was created by a dickhead, because it declares that it semantically returns a boolean type but then actually returns three different unsigned chars (0, 1, 255). EXCEPT THAT IT ONLY DOES THIS IF __cplusplus IS NOT #DEFINED, but you wouldn't know that unless you went digging somewhere else (back in src/mud.h)! If _cplusplus *is* defined, then you have a function that actually returns a bool, and each of those "return BERR;"s is actually just returning true because anything not zero is true in C++. And then of course the compiler is then trying to convert those real booleans back into integers so that they can be compared against 255, except that true converts to 1 and false converts to 0, neither of which will equal 255. Sigh.

Getting that warning means that you're using a C++ mode compiler. You might try switching to a C compiler instead.

If I were going to fix this for real, I'd make check_playing declare that it returns unsigned char (or int) so that it stops converting into booleans instead of doing these only-sometimes-fake "bool" shenanigans.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Alyce   (43 posts)  [Biography] bio
Date Reply #2 on Fri 09 Sep 2016 03:25 AM (UTC)
Message
well im compiling in cygwin for the moment. My bandwidth is severely limited right now so it's not possible to add any packages or change any. When I put it on an actual server with the proper libraries and stuff, I am assuming this will go away correct?
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 09 Sep 2016 09:07 PM (UTC)
Message
No, I doubt it. How are you compiling? If you are using g++ you are compiling in C++ mode. If gcc then it is C mode. Also the suffix of your source file might affect it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Alyce   (43 posts)  [Biography] bio
Date Reply #4 on Sat 10 Sep 2016 01:15 AM (UTC)
Message

gcc-core                                5.4.0-1                          OK
gcc-g++                                 5.4.0-1                          OK
[Go to top] top

Posted by Kasji   (35 posts)  [Biography] bio
Date Reply #5 on Sat 10 Sep 2016 05:25 AM (UTC)

Amended on Sat 10 Sep 2016 05:26 AM (UTC) by Kasji

Message
So, BERR is defined as the number 255.

check_playing() returns a bool.

In C, in Smaug, bool is type defined as an int or maybe short int. So check_playing() == BERR in C would be comparing 2 numbers.
[EDIT] Er, unsigned char like Fiendish said.

You're using C++ though, and as such, you're comparing a true/false from check_playing() to a number.

The change I made on my code was to change check_playing() from a bool return value to an int return value.

int check_playing(Blah blah blah)
{
Stuff
}
[Go to top] top

Posted by Alyce   (43 posts)  [Biography] bio
Date Reply #6 on Sat 10 Sep 2016 05:38 AM (UTC)
Message
That is what I did at first to get rid of the warnings, and it worked to that extent.. however in doing so, when connecting to a link-dead player, or when logging on when connected it triggered segmentation faults.

It works just fine with the warnings there, it's just an eye sore when compiling.
[Go to top] top

Posted by Kasji   (35 posts)  [Biography] bio
Date Reply #7 on Sat 10 Sep 2016 06:11 AM (UTC)
Message
I'm not running Smaug, so I can't say for sure how different our codes are, but... Recall that as a bool, check_playing will always evaluate as false. It's possible that something inside the if statement block is causing the crash, but it never happens while check_playing returns a bool because that block never gets executed (due to the if statement always evaluating as false).
[Go to top] top

Posted by Alyce   (43 posts)  [Biography] bio
Date Reply #8 on Sat 10 Sep 2016 06:34 AM (UTC)
Message
I will be able to do more in depth looking with GDB but with my limited bandwidth I can't get it downloaded to my cygwin packages... I'll have to wait for a proper server
[Go to top] top

Posted by Kasji   (35 posts)  [Biography] bio
Date Reply #9 on Sun 11 Sep 2016 10:38 PM (UTC)
Message
A trick that I use a lot when I don't have gdb available (for a while my mud wasn't dumping cores), is bug messages. I place bug messages around the area of code where the crash is happening, and can use that to narrow down the line that is causing the crash since I know the crash has to be happening before a bug message if it doesn't print out, or after a particular bug message if it does print out.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


22,285 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]