Yay INT2BYTE!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PaulBlay
    Knight
    • Jan 2009
    • 657

    Yay INT2BYTE!

    I've been putting in a lot of debug-mode checking on type conversion into my code and it's finally paid off.

    Code:
    #ifndef NDEBUG
    # define INT2BYTE(P) int2byte(P)
    #else
    # define INT2BYTE(P) (byte) (P)
    #endif
    
    #ifndef NDEBUG
    byte int2byte(const int P)
    {	
    	assert(P >= 0);
    	assert(P <= 255);
    	return((byte) P);
    }
    #endif
    It caught that the ego_item data I'm using allows negative to hit / to dam bonuses but the ego_item_type struct in Vanilla Angband stores them in byte (unsigned char) variables.
    Currently turning (Angband) Japanese.
  • zaimoni
    Knight
    • Apr 2007
    • 590

    #2
    May I invite you to the darkness that is C++?

    From Zaiband:
    Code:
    /*
     * Class to automate runtime checking of valid usage of m_idx against mon_list
     * It has some obnoxious traits, so use only when mon_list+m_idx_type needs to work automatically.
     */
    class m_idx_type
    {
    	s16b _m_idx;
    public:
    	m_idx_type() {};
    	m_idx_type(s16b src) : _m_idx(src) {assert(0<src);assert(mon_max>src);};
    	void operator=(s16b src) {assert(0<src);assert(mon_max>src);_m_idx = src;};
    	operator s16b() const {return _m_idx;};
    	s16b operator--() {assert(1<_m_idx); return --_m_idx;}
    	s16b operator--(int) {assert(1<_m_idx); return _m_idx--;}
    };
    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

    Comment

    • PaulBlay
      Knight
      • Jan 2009
      • 657

      #3
      Originally posted by zaimoni
      May I invite you to the darkness that is C++?
      Haha, well not until I've reached beta with C at any rate.

      One programming language is more than enough to learn at a time.
      Currently turning (Angband) Japanese.

      Comment

      Working...
      😀
      😂
      🥰
      😘
      🤢
      😎
      😞
      😡
      👍
      👎