Norberto Alfredo Bensa wrote:
If this is not the right place to ask for gnu pascal port to djgpp please let me know where can I do it...
It is. (And, BTW, this problem is not DJGPP specific, anyway.)
Is this a bug in gnu pascal or just a "feature" I didn't know about?
The code below is intented to find the prime numbers between 1 and 100 (... ok 1 isn't really a prime number but who cares? ;-)), but it doesn't work... it just displays 1.... Now if you add "h :=1;" just after "j" is initialized, then the program works!!!... it doesn't make sense, at least for me ... (it worked unmodified with the gpc dist from gpc112b.zip)
The problem is the following: You use a for loop counter (h) after the loop, and in Pascal this is undefined (this might be one of the most despised features of Pascal, but it has its reasons). Therefore, it's quite possible that one compiler does what you want and another compiler (or another version of the same compiler) doesn't.
For a solution, I suggest to convert the for loop into a while loop:
h := 1; while h <= j-1 do begin ... Inc (h) end;
Frank
Frank Heckenbach writes: | Norberto Alfredo Bensa wrote: | The problem is the following: You use a for loop counter (h) after | the loop, and in Pascal this is undefined (this might be one of the | most despised features of Pascal, but it has its reasons). | Therefore, it's quite possible that one compiler does what you want | and another compiler (or another version of the same compiler) | doesn't. |
Isn't it also wrong to attempt to modify a FOR loop index variable inside the body for the FOR statement?
for h := 1 to j-1 do if 2*p[h]>i then h := j { <------- } else if i mod p[h]= 0 then break;
I thought this was not allowed in Pascal, but I see gpc accepts it.