Update of bug #13805 (project freeciv):

             Assigned to:                    None => mbook                  


Follow-up Comment #1:

This patch is good, but you can reduce references to the
global variable 'settings' even more by using helper
functions to get a setting pointer from a setting id:

struct settings_s *setting_by_number(int id)
  if (!(0 <= id && id < SETTINGS_NUM) {
    return NULL;
  return settings + id;

(The expression 'settings + id' is the same as
'&settings[id]', since ptr[x] == *(ptr + x)).

To get the "id" from a setting pointer, you use
pointer arithmetic again:

int setting_number(const struct setting_s *op)
  if (!op) {
    return -1;
  return op - settings;

Some description of pointer arithmetic is here


if you are unfamiliar with the concept.

Ideally we would want to completely remove the extern
reference to 'settings' from settings.h.

Good job using git. :)



Reply to this item at:


  Message sent via/by Gna!

Freeciv-dev mailing list

Reply via email to