September 2018
Intermediate to advanced
328 pages
9h 10m
English
Create a new directory in your /book-examples directory named /compile-with-llvm. Create a new file in the /compile-with-llvm directory named main.cpp and populate it with the following contents:
#include <stdbool.h>#define BOUNDS 255#define RECT_SIDE 50#define BOUNCE_POINT (BOUNDS - RECT_SIDE)bool isRunning = true;typedef struct Rect { int x; int y; char direction;} Rect;struct Rect rect;void updateRectLocation() { if (rect.x == BOUNCE_POINT) rect.direction = 'L'; if (rect.x == 0) rect.direction = 'R'; int incrementer = 1; if (rect.direction == 'L') incrementer = -1; rect.x = rect.x + incrementer; rect.y = rect.y + incrementer;}extern "C" {extern int jsClearRect();extern int jsFillRect(int x, int y, int width, int height);Read now
Unlock full access