jeudi 2 novembre 2017

Simple for loop causing segmentation fault

I really am quite lost on this one, I haven't ran into anything like it before. Here is the code segment that when not commented out causes my program to have a segmentation fault:

for (int i = 0; i < page_frame_count; i++) {
  cout << i << endl;
}

Now my first assumption would be this is an issue with page_frame_count (which is an int defined earlier), however, I added in this line before it and it printed the exact value it should be:

cout << page_frame_count << endl;

Output: 5

The interesting thing is, when I have the for loop uncommented it does not even print the cout statement it just immediately gives me a segmentation fault. Even changing the for loop to the following causes a segmentation fault:

for (int i = 0; i < 5; i++) {

I even tried changing the name of the counter in case that was the issue but this causes a segmentation fault as well:

for (int never_used_variable = 0; never_used_variable < 5; never_used_variable++) {

If anyone has any suggestions I'd love to hear them because I really never have seen an issue like this before.

Aucun commentaire:

Enregistrer un commentaire