Няшная / Говнокод #3260 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
/* TODO: make this into something smarter than a linked list */
typedef struct bunchOfInstances_t {
    ncInstance * instance;
    int count; /* only valid on first node */
    struct bunchOfInstances_t * next;
} bunchOfInstances;

ncInstance * get_instance (bunchOfInstances **headp)
{
    static bunchOfInstances * current = NULL;
    
    /* advance static variable, wrapping to head if at the end */
    if ( current == NULL ) current = * headp;
    else current = current->next;
    
    /* return the new value, if any */
    if ( current == NULL ) return NULL;
    else return current->instance;
}

Запостил: raorn raorn, (Updated )

Комментарии (5) RSS

  • typedef struct bunchOfInstances_t

    Зачем лишний typedef? Не хватает обычного struct bunchOfInstances_t {....}?
    Ответить
    • >Зачем лишний typedef?
      В Си это нужно, чтобы писать просто "bunchOfInstances", а не "struct bunchOfInstances_t"
      Ответить
      • ну не обязательно какбэ, допустим в сишарпе было бы подобное прекрасно:

        typedef String Path;

        и далее:

        Path Path.Combine(Path path1, Path path2);

        и т. д.

        Или например

        typedef int size;

        Чтобы чётко понимать, чтО имеешь перед глазами, а не какое-то бесполое "int". Своего рода наследование от примитивных типов, короче.
        Ответить
        • ну вот, а в С надо обязательно, структуры объявляются как
          struct mystruct myvar;
          Ответить

Добавить комментарий

Семь раз отмерь — один отрежь, guest!

    А не использовать ли нам bbcode?


    8