Prof A Olowofoyeku wrote:
On 4 Mar 2005 at 18:43, Waldek Hebisch wrote:
[...]
GPC allows the following:
program foo; type fsi = function(s : string): integer; var fp : fsi; i : integer; function GetProcAddress : pointer; begin GetProcAddress := nil end; begin fp := fsi(GetProcAddress); i := fp('') end .
Of course, since my `GetProcAddress' return nil it will crash at runtime. However, with proper external declaration of `GetProcAddress' and `LoadLibrary' and assuming that fsi is correct it should work. On Windows you have to remember to use correct calling convention, but that is not different that calling external functions via import librarires.
So, AFAICS you can not entiterly omit info about arguments
[...]
So, how come gcc can do it? Is this a peculiarity of C compilers, or is it something unique to gcc than cannot possibly be enabled in gpc?
1) All parameters in C are passed by value. Pascal has both "by value" and "var" parameters, and the compiler needs declarations to correctly pass arguments. Also, Pascal constants represent values, and parameter types allow to
2) AFAIK even on Windows you need to specify correct calling convention, otherwise if it is different then the default the program will crash
3) Declaring functions without giving parameter types is considered bad practice in C. You _are_ allowed to declare function having variable parameters (number of parameters and their types vary), but that is different then no declaration
4) You can define variable argument functions in Pascal:
type fsi = function(...): integer;
The call will be performed as C call. Note that calling convention must match, and that constant arguments may go wrong (gpc tries to do what C compiler will do, but has less information).