PDA

View Full Version : Minor SDL translation question (no hablo C muy bien)



masonwheeler
26-02-2008, 04:34 PM
I'm trying to translate an SDL add-on library to Object Pascal, but I'm running up against some very strange syntax.

while (0 >= (val = SDL_PollEvent(event)))

I have no idea what this conditional is supposed to be evaluating. It looks like it's checking the numeric result of an assignment operation? ("val" is declared as an integer.)

Any idea what's going on here?

cronodragon
26-02-2008, 04:42 PM
Yes, in C (val = SDL_PollEvent(event)) is evaluated as val after the assigment is executed. You can translate it as:

val := SDL_PollEvent(event);

while 0 >= val do
// do something, probably uses val here again
val := SDL_PollEvent(event);
end;

val is assigned before entering the while and at the end of the while, because val is assigned in the C statement for every iteration.

masonwheeler
26-02-2008, 04:51 PM
I see! And looking through the code, and the headers, it appears that the function only returns 1 or 0, and the only other thing "val" is used for is to provide the return value. Therefore, I can eliminate the variable altogether, test the function's result directly in the loop, and simply end with "result := 1".

Thanks!

technomage
26-02-2008, 06:09 PM
This has already been done :D

I just haven't had time to commit the source to the JEDI-SDL library.

I'll try and get round to it this weekend :D

masonwheeler
26-02-2008, 07:53 PM
Well, I just finished it at my end. Problem is, I can't get it to work (http://pascalgamedevelopment.com/viewtopic.php?p=41974#41974). Any help?