Skip to content

Instantly share code, notes, and snippets.

@nickmertin
Created May 2, 2020 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickmertin/cac23c15b4f29f8f3ba00cdf5d0351bb to your computer and use it in GitHub Desktop.
Save nickmertin/cac23c15b4f29f8f3ba00cdf5d0351bb to your computer and use it in GitHub Desktop.
VEXcode sample for causing a Prefetch Error
/*----------------------------------------------------------------------------*/
/* */
/* 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