Created
October 2, 2012 14:16
-
-
Save aprell/3819480 to your computer and use it in GitHub Desktop.
Protected blocks in C
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
// Make sure that before is executed before a dependent block or statement | |
// and after is executed afterwards | |
#define PROTECTED(before, after) \ | |
for (int __i = ((before), 0); !__i; (after), __i++) | |
int main(void) | |
{ | |
int i, sum = 0; | |
#define N 100 | |
PROTECTED(assert(sum == 0), assert(sum == N*(N+1)/2)) { | |
for (i = 1; i <= N; i++) { | |
sum += i; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment