Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Created July 23, 2011 06:20
Show Gist options
  • Select an option

  • Save chadbrewbaker/1101098 to your computer and use it in GitHub Desktop.

Select an option

Save chadbrewbaker/1101098 to your computer and use it in GitHub Desktop.
Bug in GCC goto parsing or the C99 standard?
#define N 100
int perm[N];
void gcc_goto_issue(){
int i,start, current;
for(i=0;i<N;i++){
start = perm[i];
current = perm[start];
long counter = 0;
while(start != current){
if(current < start) goto loopEnd;
current = perm[current];
}
// Do something here with this permutation cycle
// as we haven't seen it yet.
loopEnd:
// When using i686-apple-darwin10-gcc-4.2.1
// the compiler gives an error unless I uncomment the next line.
//i=i;
}
}
int main () {
int i;
for(i=0;i<N;i++)
perm[i]= i; //Input is a random permutation
gcc_goto_issue();
}
@chadbrewbaker
Copy link
Author

If you put a single ";" after the goto label it compiles fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment