semiversus / jeg

NES emulator with focus at hardware abstraction, testability and performance
MIT License
9 stars 2 forks source link

macro leftovers? #21

Closed semiversus closed 6 years ago

semiversus commented 6 years ago

I found some do{ ... }while(false) constructs in code. Are these left overs from former macro definitions or may I'm missing something?

GorgonMeducer commented 6 years ago

“do { } while(false)” and “do {} while(0)” are very useful structures which have following benefits:

  1. they wrap multiple statement as one
  2. you can add “if (condition) break;” to do validation, e.g.

do { if () { break; } if () { break; } ... //! it’s safe to do what we want to do ... } while(false);

  1. It’s possible to limit the range (life-time) of a variable
  2. they make a code segment obviouse and limit the range of the code segment
  3. they can be easily extracted as functions / macros
semiversus commented 6 years ago

seems legit while development but I think it's cleaner without this construction. Is it OK for you to remove in a future point of time when things getting stable?

GorgonMeducer commented 6 years ago

I reviewed the code segments you pointed out, all of these do {} while() structure have functionalities, so they cannot be removed. E.g.

The first three you mentioned are used for validation purpose (checking input variable conditions at runtime, even things getting stable, those validations are required for making code robust). The final one is used for limiting the life cycle of a local variable ‘chTempIndex’.

If you agree, I will remove those do {} while() structures which have no obviouse functionalities.

semiversus commented 6 years ago

OK