1

I'm using the C libYAML library for handling YAML configuration files, and I a little confused about this struct element in its code:

/** The stack of mapping pairs (key, value). */
struct {
    /** The beginning of the stack. */
    yaml_node_pair_t *start;
    /** The end of the stack. */
    yaml_node_pair_t *end;
    /** The top of the stack. */
    yaml_node_pair_t *top;
} pairs;

It uses three pointers, start, end, and top. Both start and end seem obvious, they're the beginning and end of the region of data, but what is top?

(For reference, this code appears at line 741 here.)

Alexis King
  • 43,109
  • 15
  • 131
  • 205

1 Answers1

3

Start and end refer to the maximum boundaries of the stack. The top is a dynamic pointer referring to the current position, and changes as you call nested levels of functions.

TJD
  • 11,800
  • 1
  • 26
  • 34
  • Ah, that would make sense. So if a pointer is within the stack, less than `end`, but greater than `top`, it isn't used yet? – Alexis King Feb 12 '13 at 02:33
  • @JakeKing correct, except it would depend on the implementation details of the stack - it is free to grow forwards from `start` to `end`, or backwards from `end` to `start`. And that's assuming `end` is greater than `start`. – paddy Feb 12 '13 at 02:35