What C++ HeapHop supports

HeapHop does not compile your code. It runs a part of C++ that covers the linked-list, stack, queue and tree programs of a first data-structures course. Anything outside that part stops with a message that names the line, so a picture is never drawn from code HeapHop did not understand.

Program structure

ConstructExampleStatus
#include, using namespace std;#include <iostream>yes (ignored)
int main() { ... return 0; }yes
Free functions, recursionint length(Node* n)yes
Pass by value and by referencevoid push(Node*& head, int v)yes
Function prototypesvoid display(Node* head);yes
Global variablesNode* head = NULL; at file levelyes
Multiple files, headers of your own#include "list.h"no

Types

ConstructExampleStatus
int, bool, char, double, floatyes
stringstring name;yes (assign, compare, print, +, .length(), .size(), .empty(), reading one character with s[i]; changing one character is not supported yet)
PointersNode* p, Node *p, int* qyes
Pointer to pointervoid push(Node** headRef, int v), *headRef = n;yes
#define SIZE 100used as an array size or a numberyes (numeric constants only)
struct with fieldsstruct Node { int data; Node* next; };yes
typedef struct { ... } Node;yes
Constructors with initialiser list or bodyNode(int d) : data(d), next(nullptr) {}yes
class, public:, private:, protected:class LinkedList { ... };yes
Member functions, thislist.insertAtEnd(5), this->headyes
Methods defined outside the classvoid LinkedList::display() { ... }yes
Destructors~LinkedList() { ... }yes
Objects on the stackLinkedList list;yes
Fixed-size arrays, new T[n], delete[]int a[5];yes
Arrays passed to functions, pointers set to an arrayvoid sort(int a[], int n), int* p = arr;yes (the function works on the caller's array)
Two-dimensional arraysint adj[5][5] = {{0, 1}, {1, 0}};, void bfs(int g[][5], int s), a member int adj[5][5];yes (up to 1000 cells; no arrays of objects; one {...} per row)
constconst int MAX = 5;yes (accepted, not enforced)
Templatestemplate <class T> class Nodeno (none of the lab files use them)
public: / private: access rulesaccepted, not enforced (HeapHop assumes the code already compiles)
Member objects that have their own constructorclass A { B b; };no (use a pointer member)
Inheritance, virtual functionsno
Operator overloading, friend functionsno
STL containersvector, list, stack, queueno
References as variablesint& r = x;no (reference parameters work)

Statements

ConstructStatus
Declarations with or without initialiseryes
Several declarators in one statement (Node *a, *b;)yes
Assignment, +=, -=yes, also *=, /=, %=
if / else if / elseyes
while, foryes
do ... whileyes
switch / case / defaultyes
break, continueyes
returnyes
new, deleteyes
cout << ... << endl;yes, with exact newlines
cin >> x;, getline(cin, s);, cin.ignore();yes. The student types everything the program will read into the "Program input" box before running. Running out of input, or text where a number is expected, stops the trace with a notice
goto, exceptions (try/catch)no

Expressions

ConstructStatus
+ - * / %, comparisons, && || !yes
++x, x++, --x, x--yes
p->field, obj.field, *p, &x, a[i]yes
nullptr, NULL, true, false, integersyes
Library functions max(a, b), min(a, b), abs(x), swap(a, b)yes (a program's own function of the same name wins)
Character literals ('a'), decimal numbers (3.5)yes
String literals with escapes ("a\n")yes
Ternary c ? a : byes
Chained assignment (head = tail = n;)yes
Pointer arithmetic (p++, p + 1), comparing pointers with <no (use p[i] or p = p->next)
sizeof, casts, bitwise operators, the comma operatorno

Runtime behaviour HeapHop shows on purpose

SituationWhat HeapHop doesStatus
Following a null pointerStops with an error step at that line; earlier steps stayyes
Using an object after deleteError step "use after delete"yes
delete twiceError step "double delete"yes
A variable used before it has a valueShown as ?; following such a pointer is an error stepyes
A node no pointer can reachMarked as leakedyes
Very long runs or infinite loopsTrace is cut at a limit with a "trace truncated" noticeyes

Structures HeapHop recognises and draws specially

StructureHow it is recognisedDrawn as
Singly, doubly, circular linked listone self-pointer; or two that mirror each otherone horizontal row
Binary tree (BST, AVL)two self-pointers that do not mirror each other (left / right)parents above children
Arrays of values or pointers: local, inside an object, or made with new[]any such arraya row of cells in the drawing area, with its indexes; ints the program uses as subscripts of that array (a[j], arr[top]) are tags above their cell; cells a step read are outlined; pointer cells have arrows (chains hanging from cells are drawn one column per cell); an array named like a heap is also drawn as a tree
2-D arraysany array of arraysa grid with row and column numbers; ints used in the first subscript tag their row, ints used in the second tag their column
Graphsa square 2-D array, or an array of list heads, whose name (or class) contains adj, graph, edge, cost or weightalso drawn as numbered vertices on a circle joined by edges (arrows if one-way, weights if any); arrays named visited / inMST / done fill the vertices, dist / key / indegree / component label them, and the edge being examined is amber

Step limits

A trace stops with a "trace truncated" notice at 2000 steps, 500 rounds of one loop, 64 nested calls, 500 live heap objects or 20000 printed characters.

Known difference from a real compiler

Real C++ gives unpredictable results for the mistakes above (it may crash, or appear to work). HeapHop always stops and explains, because that is more useful for learning.