Skip to content

Instantly share code, notes, and snippets.

@raytroop
Created September 29, 2019 06:00
Show Gist options
  • Save raytroop/0212bc5ee3f7d099c5d52ed81b9ddd35 to your computer and use it in GitHub Desktop.
Save raytroop/0212bc5ee3f7d099c5d52ed81b9ddd35 to your computer and use it in GitHub Desktop.
Conditional compilation
#include <iostream>

#define na 4

int main() {
  int a[na];

  a[0] = 2;
  for (int n = 1; n < na; n++) a[n] = a[n-1] + 1;

#ifdef DEBUG
  // Only kept by preprocessor if DEBUG defined
  for (int n = 0; n < na; n++) {
    std::cout << "a[" << n << "] = " << a[n] << std::endl;
  }
#endif 
  
  return 0;
}
$ g++ -Wall -Wextra -Wconversion conditional.cpp -o conditional
$ ./conditional
$ g++ -Wall -Wextra -Wconversion conditional.cpp -o conditional -DDEBUG
$ ./conditional
a[0] = 2
a[1] = 3
a[2] = 4
a[3] = 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment