"Open Macro Library"

Syntax quick tour

lstack (list-based stack implementation)

#define OML_DEBUG_LEVEL OML_LEVEL_DEBUG
#include "oml_debug.h"
#include "oml_lstack.h"

#include <stdio.h>
#include <stdlib.h>

oml_define_lstack(int);

oml_lstack(int) h;

#define SIZE 4
int values[SIZE];

int main(int argc, char **argv) {
  int v;

  oml_lstack_init(&h);

  printf("Size of lstack: %d\n", oml_lstack_size(&h));
  oml_lstack_push(&h, 1024);
  printf("Size of lstack: %d\n", oml_lstack_size(&h));
  oml_lstack_pop(&h);

  printf("Size of lstack: %d\n", oml_lstack_size(&h));

  oml_lstack_push(&h, 4);
  oml_lstack_push(&h, 7);
  oml_lstack_push(&h, 1);
  oml_lstack_push(&h, 3);
  printf("Size of lstack: %d\n", oml_lstack_size(&h));

  oml_lstack_pop(&h);
  oml_lstack_pop(&h);
  oml_lstack_pop(&h);
  oml_lstack_pop(&h);
  printf("Size of lstack: %d\n", oml_lstack_size(&h));

  if (oml_lstack_pop(&h) != OML_E_EMPTY) {
    printf("Should have experienced an error on empty heap\n");
    return -1;
  }

  int i;
  oml_lstack_iterator(int) it;

  for (i = 0; i < SIZE; ++i) {
    values[i] = rand();
    printf("Inserting %d\n", values[i]);
    oml_lstack_push(&h, values[i]);
  }


  printf("VStack dump:\n");
  oml_lstack_begin(&h, &it);
  for (; oml_lstack_has_value(&h, &it); oml_lstack_next(&h, &it)) {
    oml_lstack_get_next(&h, &it, &v);
    printf("  List elem: %d\n", v);
  }

  for (i = 0; i < SIZE; ++i) {
    oml_lstack_front(&h, &v);
    oml_lstack_pop(&h);
    printf("Extracted: %d, expected: %d\n", v, values[SIZE - 1 - i]);
  }
  printf("Size of lstack: %d\n", oml_lstack_size(&h));

  oml_lstack_cleanup(&h);


  printf("Test successful\n");
  return 0;
}

Latest news

2009-01-25
Deadline exception

2009-01-24
Exceptions for C Package

2009-01-16
Exceptions for the C language

2007-03-06
Syntax quick tour update.





Last update:
March 2, 2010