Created
May 2, 2020 14:19
-
-
Save nickmertin/cac23c15b4f29f8f3ba00cdf5d0351bb to your computer and use it in GitHub Desktop.
VEXcode sample for causing a Prefetch Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*----------------------------------------------------------------------------*/ | |
/* */ | |
/* Module: main.cpp */ | |
/* Author: Nick Mertin */ | |
/* Created: Fri Apr 24 2020 */ | |
/* Description: V5 project */ | |
/* */ | |
/*----------------------------------------------------------------------------*/ | |
// ---- START VEXCODE CONFIGURED DEVICES ---- | |
// ---- END VEXCODE CONFIGURED DEVICES ---- | |
#include "vex.h" | |
using namespace vex; | |
int *var; | |
void foo() { | |
int x; | |
var = &x; | |
} | |
void bar2() { | |
// Because of our (artificially simulated) bad luck, this overwrites the | |
// address of the next line of code in main() that bar() will attempt to | |
// return to. | |
*var = 0; | |
} | |
void bar() { | |
bar2(); | |
} | |
int main() { | |
// Initializing Robot Configuration. DO NOT REMOVE! | |
vexcodeInit(); | |
// This sets var. | |
foo(); | |
// The error happens when this call tries to return. | |
bar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment