Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old June 27, 2010, 12:46   #41
nppangband
NPPAngband Maintainer
 
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
nppangband is on a distinguished road
Quote:
Originally Posted by Pete Mack View Post
Yep. There is no reason to code to a 20 year old standard when a 10 year old standard is available.
In looking at h-basic.h, line 157 of the code is redundant:

155 * C++ defines its own bool type, so we hack around it */
156 #undef bool
157 #define bool bool_hack

a coule lines later, bool is re-defined anyway, either through stdbool.h, or it is defined as a char for the systems that don't have STDBOOH_H...

/*
* Use a real bool type where possible
*/
#ifdef HAVE_STDBOOL_H

#include <stdbool.h>

#define TRUE true
#define FALSE false

#else

/* Use a char otherwise */
typedef char bool;

#undef TRUE
#undef FALSE

#define TRUE 1
#define FALSE 0
nppangband is offline   Reply With Quote
Old June 27, 2010, 16:32   #42
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,936
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by nppangband View Post
In looking at h-basic.h, line 157 of the code is redundant:

155 * C++ defines its own bool type, so we hack around it */
156 #undef bool
157 #define bool bool_hack

a coule lines later, bool is re-defined anyway, either through stdbool.h, or it is defined as a char for the systems that don't have STDBOOH_H...
"bool" doesn't get redefined-- the #define bool bool_hack means that "bool_hack" is defined later, and everywhere in Angband that uses "bool" is actually using "bool_hack". I believe this is to work around people trying to use C++ compilers with Angband that define their own bool types.
__________________
takkaria whispers something about options. -more-
takkaria is offline   Reply With Quote
Old June 27, 2010, 23:18   #43
nppangband
NPPAngband Maintainer
 
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
nppangband is on a distinguished road
Quote:
Originally Posted by takkaria View Post
"bool" doesn't get redefined-- the #define bool bool_hack means that "bool_hack" is defined later, and everywhere in Angband that uses "bool" is actually using "bool_hack". I believe this is to work around people trying to use C++ compilers with Angband that define their own bool types.
You are right. I know you & the the vanilla dev team know much more about this than I do. I can make the Angband source do what I want, but that is the limit of my programming knowledge.

That line gave me half of a page of compiler errors. "bool_hack" doesn't seem to be defined or exist anywhere else in the angband source. Actually, according to google, it doesn't exist anywhere else in the world either. So I removed it and all the compiler errors went away. Am I missing something & do I need bool_hack defined?

Am I reading that other code correctly? It looks like the line before undefines bool, and a couple lines later, if HAVE_STDBOOL_H, bool is defined by stdbool.h, and if I don't, it is defined as a bool. So why would bool_hack need to be defined?

Thanks.
nppangband is offline   Reply With Quote
Old June 28, 2010, 00:57   #44
zaimoni
Knight
 
zaimoni's Avatar
 
Join Date: Apr 2007
Posts: 590
zaimoni is on a distinguished road
Quote:
Originally Posted by takkaria View Post
"bool" doesn't get redefined-- the #define bool bool_hack means that "bool_hack" is defined later, and everywhere in Angband that uses "bool" is actually using "bool_hack". I believe this is to work around people trying to use C++ compilers with Angband that define their own bool types.
A correct workaround is
1) ditch the #define (which invokes undefined behavior all versions of C++)
2) only bother with typedef'ing bool in C
3) Keep the rest of the code.
__________________
Zaiband: end the "I shouldn't have survived that" experience. V3.0.6 fork on Hg.
Zaiband 3.0.10 ETA Mar. 7 2011 (Yes, schedule slipped. Latest testing indicates not enough assert() calls to allow release.)
Z.C++: pre-alpha C/C++ compiler system (usable preprocessor). Also on Hg. Z.C++ 0.0.10 ETA December 31 2011
zaimoni is offline   Reply With Quote
Old June 28, 2010, 01:02   #45
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,422
Donated: $40
Pete Mack is on a distinguished road
A better workaround is to ditch all the stuff around bool, and change the compiler option -c89... to -c99

Then do a global replace TRUE by true and FALSE by false.
The messing around with non-standard boolean types is a highly undesirable archaism.
Pete Mack is offline   Reply With Quote
Old June 28, 2010, 01:08   #46
zaimoni
Knight
 
zaimoni's Avatar
 
Join Date: Apr 2007
Posts: 590
zaimoni is on a distinguished road
Requiring C99 means dropping support for both MSVC (C89 compiler only) and native MingW32 (recent standard header releases don't compile as C99).
__________________
Zaiband: end the "I shouldn't have survived that" experience. V3.0.6 fork on Hg.
Zaiband 3.0.10 ETA Mar. 7 2011 (Yes, schedule slipped. Latest testing indicates not enough assert() calls to allow release.)
Z.C++: pre-alpha C/C++ compiler system (usable preprocessor). Also on Hg. Z.C++ 0.0.10 ETA December 31 2011
zaimoni is offline   Reply With Quote
Old June 28, 2010, 01:26   #47
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 5,422
Donated: $40
Pete Mack is on a distinguished road
MSVC doesn't support full c99, but it does support the intersection of c99 with C++.
So bool is ok, but it's a built-in. (Dont' include stdbool.h)
Pete Mack is offline   Reply With Quote
Old July 7, 2010, 02:06   #48
nppangband
NPPAngband Maintainer
 
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
nppangband is on a distinguished road
I have a bug that should be simple to fix, but I don't know where to do it.

The game crashes if I use the up, down, left, or right direction keys on my keyboard without the numlock on, but the diagonal direction keys work fine. It crashes on this line, in textui_process_command.

assert(p_ptr->command_cmd >= CHAR_MIN && p_ptr->command_cmd <= CHAR_MAX);

If the numlock is on, the p_ptr->command is 59, and if numlock is off, the direction keys are between 138-141, and the game crashes. Again, the diagonal keys work fine either way

Isn't there a pref file that converts certain keyboard commands like this? I know the 138 is above the 127 limit, but I can't figure out why it would be crashing the game. I have assert.h declared in h-basic.h just like in Angband.

Any thoughts or suggestions? I am stumped. Thanks.
nppangband is offline   Reply With Quote
Old July 7, 2010, 04:01   #49
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 54
Posts: 7,863
Donated: $60
Nick will become famous soon enough
Quote:
Originally Posted by nppangband View Post
assert(p_ptr->command_cmd >= CHAR_MIN && p_ptr->command_cmd <= CHAR_MAX);

If the numlock is on, the p_ptr->command is 59, and if numlock is off, the direction keys are between 138-141, and the game crashes. Again, the diagonal keys work fine either way

Isn't there a pref file that converts certain keyboard commands like this? I know the 138 is above the 127 limit, but I can't figure out why it would be crashing the game. I have assert.h declared in h-basic.h just like in Angband.
The relevant file is pref-win.prf, IIRC. I have had endless troubles with it and arrow keys.
If I understand assert correctly, that is what it does - if the condition is not satisfied, it terminates the program.
Good luck
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Old July 7, 2010, 04:34   #50
nppangband
NPPAngband Maintainer
 
Join Date: Dec 2008
Location: Stat Gain, Angband
Posts: 926
nppangband is on a distinguished road
Quote:
Originally Posted by Nick View Post
The relevant file is pref-win.prf, IIRC. I have had endless troubles with it and arrow keys.
If I understand assert correctly, that is what it does - if the condition is not satisfied, it terminates the program.
Good luck
Thanks! With that help I found it. Strangely, utting in the updated pref-win.prf fromthe current angband into NPP causes the crashes. If I keep the current one from NPPAngband it works fine.
nppangband is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to understand Ranger playing mechanics dormouse Vanilla 5 December 15, 2009 12:43
Angband Code Interface to GUI meeshoo Vanilla 50 February 3, 2009 18:18
I finally understand how diving quicker can be "safer" Wraitheist Vanilla 13 September 19, 2008 18:25
strange C code in Angband (am I reading this right?) will_asher Idle chatter 3 February 4, 2008 10:07
Angband source branches vs trac ctate Vanilla 1 July 14, 2007 12:43


All times are GMT +1. The time now is 09:55.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.