Search code examples
sdlpascalfreepascal

What does @ before a parameter in a function call means in Pascal


I have stumbled into multiple examples of Pascal code (FPC compiler mode) where the '@' symbol is sometimes used before the name of a parameter in a function/procedure call, and I couldn't find what this means. Sometimes i even saw it being used with a variable which had not been declared yet. For instance :

procedure displayImage ( var window , image : PSDL_SURFACE );
    var destination_rect : TSDL_RECT ;
BEGIN
    {Setting of the x,y,w and h parameters of the destination_rect variable}
    SDL_BlitSurface (image , NIL , window , @destination_rect);
    SDL_Flip (window)
END;

   

SDL_PollEvent (@event); //The event variable hasn't been declared or initialized prior to this, yet this seems to work
if event.type_ = SDL_MOUSEBUTTONDOWN then
    {Do stuff}
if event.type_ = SDL_QUITEV then
    {Quit program}

I suppose this might be a SDL quirk, since every time I encountered this it was in a SDL related function, but I couldn't find anything about it.


Solution

  • In Borland like Pascals, the @ is the address-of operator, similar to & in C/C++.

    Additionally, the own Free Pascal dialects (fpc and objfpc) require a @ in places where in TP/Delphi you can just pass the function/method

    This was added to disambiguate a corner case where a function/method returns a procedure/method type with the same signature.

    It is one of the things in mode objfpc that hurt compatibility and don't add much (since it only solves a quite contrived corner case), which is why I avoid these modes if I can, and use {$mode delphi} as much as possible.