voidptrdance

Example code for a blog post on generic programming in C
git clone https://git.tronto.net/voidptrdance
Download | Log | Files | Refs | README

main1.c (337B)


      1 #include <stdio.h>
      2 #include "PriorityQueue.h"
      3 
      4 int priority_int(void *i) { return *(int *)i; }
      5 TDescription int_desc = { .priority = priority_int };
      6 
      7 int main() {
      8 	PriorityQueue *q = NewPriorityQueue(int_desc);
      9 	int x = -12, y = 42;
     10 	Add(q, &x);
     11 	Add(q, &y);
     12 	printf("The highest-priority element is %d\n", *(int *)Pop(q));
     13 	return 0;
     14 }