1 //===-- main.c --------------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include <stdio.h> 10 11 class Task { 12 public: 13 int id; 14 Task *next; 15 Task(int i, Task *n): 16 id(i), 17 next(n) 18 {} 19 }; 20 21 22 int main (int argc, char const *argv[]) 23 { 24 Task *task_head = NULL; 25 Task *task1 = new Task(1, NULL); 26 Task *task2 = new Task(2, NULL); 27 Task *task3 = new Task(3, NULL); // Orphaned. 28 Task *task4 = new Task(4, NULL); 29 Task *task5 = new Task(5, NULL); 30 31 task_head = task1; 32 task1->next = task2; 33 task2->next = task4; 34 task4->next = task5; 35 36 int total = 0; 37 Task *t = task_head; 38 while (t != NULL) { 39 if (t->id >= 0) 40 ++total; 41 t = t->next; 42 } 43 printf("We have a total number of %d tasks\n", total); 44 45 // This corresponds to an empty task list. 46 Task *empty_task_head = NULL; 47 48 Task *task_evil = new Task(1, NULL); 49 Task *task_2 = new Task(2, NULL); 50 Task *task_3 = new Task(3, NULL); 51 task_evil->next = task_2; 52 task_2->next = task_3; 53 task_3->next = task_evil; // In order to cause inifinite loop. :-) 54 55 return 0; // Break at this line 56 } 57