Burada bildiğim tüm hata ayıklamalarını tüketdim ve yardım isteğinde bulunmaya karar verdim. Bu, Beladys anomalisini gözlemleyip gözlemleyemeyeceğimizi gözlemlemek amacıyla, Tablo 3 ve 4 için bir FIFO algoritmasının sayfalandırılmasını amaçlayan bir okul atamasıdır.C'deki döngüler için çok tuhaf bir sorun, veriler tutarsız
int i;
srand(time(NULL));
int faults[2], threeTable[3], fourTable[4];
int p;
int beladyOccured = 0;
int beladyNot = 0;
count = 20;
for(p = 0; p < 1000; p++)
{
for(i = 0; i < 20; i++)
{
arr[i] = rand() % 5;
}
initializeTables(threeTable, 3);
faults[0] = fifo(threeTable, 3);
initializeTables(fourTable, 4);
faults[1] = fifo(fourTable, 4);
if (detectBelady(faults[1], faults[0]) == 1)
{
beladyOccured++;
printf("Belady's Anomaly occured, p is %d, i is %d, number of faults for three is %d, number of faults for four is %d, belady occurances is %d, and non-occurances is %d", p, i, faults[0], faults[4], beladyOccured, beladyNot);
}
else
{
beladyNot++;
printf("Belady's Anomaly did not occur, p is %d, i is %d, number of faults for three is %d, number of faults for four is %d, belady occurances is %d, and non-occurances is %d \n", p, i, faults[0], faults[4], beladyOccured, beladyNot);
}
}
printf("Using frame sizes 3 and 4, beladys algorithm occured %d times and did not occur %d times \n", beladyOccured, beladyNot);
return 0;
Aşağıdaki küresel bildirimleri var:
Belady's Anomaly did not occur, p is 3, i is 0, number of faults for three is 9, number of faults for four is 1, belady occurances is 1, and non-occurances is 12
Belady's Anomaly did not occur, p is 4, i is 4, number of faults for three is 10, number of faults for four is 1, belady occurances is 1, and non-occurances is 13
Belady's Anomaly did not occur, p is 3, i is 0, number of faults for three is 10, number of faults for four is 1, belady occurances is 1, and non-occurances is 14
Belady's Anomaly did not occur, p is 4, i is 0, number of faults for three is 10, number of faults for four is 1, belady occurances is 1, and non-occurances is 15
Belady's Anomaly did not occur, p is 4, i is 3, number of faults for three is 12, number of faults for four is 4, belady occurances is 4, and non-occurances is 4
Belady's Anomaly did not occur, p is 4, i is 4, number of faults for three is 10, number of faults for four is 4, belady occurances is 4, and non-occurances is 5
Belady's Anomaly did not occur, p is 5, i is 1, number of faults for three is 9, number of faults for four is 4, belady occurances is 4, and non-occurances is 6
Belady's Anomaly did not occur, p is 6, i is 4, number of faults for three is 9, number of faults for four is 4, belady occurances is 4, and non-occurances is 7
Belady's Anomaly did not occur, p is 1, i is 1, number of faults for three is 10, number of faults for four is 4, belady occurances is 4, and non-occurances is 8
Belady's Anomaly did not occur, p is 0, i is 3, number of faults for three is 12, number of faults for four is 3, belady occurances is 3, and non-occurances is 4
Belady's Anomaly did not occur, p is 1, i is 20, number of faults for three is 8, number of faults for four is 3, belady occurances is 3, and non-occurances is 5
Belady's Anomaly did not occur, p is 2, i is 20, number of faults for three is 8, number of faults for four is 3, belady occurances is 3, and non-occurances is 6
Belady's Anomaly did not occur, p is 3, i is 4, number of faults for three is 9, number of faults for four is 3, belady occurances is 3, and non-occurances is 7
Belady's Anomaly did not occur, p is 4, i is 20, number of faults for three is 7, number of faults for four is 3, belady occurances is 3, and non-occurances is 8
Belady's Anomaly did not occur, p is 5, i is 20, number of faults for three is 8, number of faults for four is 3, belady occurances is 3, and non-occurances is 9
Belady's Anomaly did not occur, p is 2, i is 0, number of faults for three is 10, number of faults for four is 3, belady occurances is 3, and non-occurances is 10
Belady's Anomaly did not occur, p is 3, i is 3, number of faults for three is 13, number of faults for four is 0, belady occurances is 0, and non-occurances is 1
Belady's Anomaly did not occur, p is 4, i is 0, number of faults for three is 11, number of faults for four is 0, belady occurances is 0, and non-occurances is 2
Belady's Anomaly did not occur, p is 5, i is 0, number of faults for three is 9, number of faults for four is 0, belady occurances is 0, and non-occurances is 3
Belady's Anomaly did not occur, p is 4, i is 4, number of faults for three is 10, number of faults for four is 0, belady occurances is 0, and non-occurances is 4
Belady's Anomaly did not occur, p is 5, i is 20, number of faults for three is 7, number of faults for four is 0, belady occurances is 0, and non-occurances is 5
Belady's Anomaly did not occur, p is 6, i is 20, number of faults for three is 7, number of faults for four is 0, belady occurances is 0, and non-occurances is 6
Belady's Anomaly did not occur, p is 7, i is 20, number of faults for three is 8, number of faults for four is 0, belady occurances is 0, and non-occurances is 7
Belady's Anomaly did not occur, p is 8, i is 20, number of faults for three is 7, number of faults for four is 0, belady occurances is 0, and non-occurances is 8
Belady's Anomaly did not occur, p is 9, i is 20, number of faults for three is 8, number of faults for four is 0, belady occurances is 0, and non-occurances is 9
Belady's Anomaly did not occur, p is 10, i is 20, number of faults for three is 8, number of faults for four is 0, belady occurances is 0, and non-occurances is 10
Belady's Anomaly did not occur, p is 0, i is 1, number of faults for three is 11, number of faults for four is 1, belady occurances is 1, and non-occurances is 11
Belady's Anomaly did not occur, p is 1, i is 0, number of faults for three is 9, number of faults for four is 1, belady occurances is 1, and non-occurances is 12
Belady's Anomaly did not occur, p is 1, i is 2, number of faults for three is 14, number of faults for four is 1, belady occurances is 1, and non-occurances is 2
Belady's Anomaly did not occur, p is 0, i is 0, number of faults for three is 10, number of faults for four is 1, belady occurances is 1, and non-occurances is 3
Belady's Anomaly did not occur, p is 1, i is 20, number of faults for three is 8, number of faults for four is 1, belady occurances is 1, and non-occurances is 4
Belady's Anomaly did not occur, p is 2, i is 3, number of faults for three is 9, number of faults for four is 1, belady occurances is 1, and non-occurances is 5
Belady's Anomaly did not occur, p is 3, i is 1, number of faults for three is 9, number of faults for four is 1, belady occurances is 1, and non-occurances is 6
Belady's Anomaly did not occur, p is 4, i is 20, number of faults for three is 8, number of faults for four is 1, belady occurances is 1, and non-occurances is 7
:
int arr[101], count;
Benim çıkış olsa şuna benzer
Temelde benim ana aşağıdaki kodu var Boşluk eksikliğinden dolayı özür diler. Düşünebildiğim tek şey, ben çağırdığım bazı işlevlerde yeniden beyan etmekteyim, ancak yerel kapsam bu yüzden önemi yok.
Bu kod hiçbir zaman sona ermez çünkü p 1000'e hiç ulaşmaz. Burada neler olup bittiği hakkında herhangi bir fikri olan var mı?
'Hatalara [4]' erişilmesi, tanımsız davranışlara neden oluyor –
, @sunqingyao'nun söylediklerinin dışında neyin yanlış olduğunu anlatabileceğim bir şey yok. – ddz
Lütfen bir [minimum eksiksiz ve doğrulanabilir örnek] gösterin (https://stackoverflow.com/help/mcve). Zaten tanımlanmış sınır dizisi erişiminin dışında, Tanımsız Davranışa neden olan gösterilmeyen işlevlerde başka hatalar da olabilir (ör. "InitializeTables"). – kaylum