Skip to content

Instantly share code, notes, and snippets.

@akiraak
Created April 20, 2011 03:48
Show Gist options
  • Save akiraak/930294 to your computer and use it in GitHub Desktop.
Save akiraak/930294 to your computer and use it in GitHub Desktop.
配列の添字にマイナスを使って参照
int funcname(int i){
static const int minus[]={-2, -1};
static const int plus[]={0, 1};
#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
assert(i >= -ARRAYSIZE(minus) && i < ARRAYSIZE(plus));
return plus[i];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment