Waldek Hebisch wrote:
Peter N Lewis wrote:
I've got a problem with GPC giving the error:
error: function result must not be a procedural type
Is there a reason for this error? The manual states:
"In Extended Pascal, function result type can be every assignable type. Of course,there are no type restrictions in GNU Pascal as well."
Since GPC supports as an extension procedural and functional types and assignments involving those types, it would seem to be covered under "every assignable type" and "no type restrictions in GNU Pascal".
Note that in Pascal there is no syntactic dictinction between function used as a value and parameterless function call. I guess that the restriction is intended to reduce resulting confusion -- if context want a function than we use function "as is", if context wants something else we call the function. In fact, any "function producing" expression has the same problem: it is not clear if the resulting function should be called or not (AFAICS the rule above is used).
In fact, the rules are a bit hairy internally, and may not be quite correct in some strange cases. I plan to work on this issue sometime and perhaps reimplement much of it. Maybe we can remove the restriction in this course (perhaps calling the function so often until the type matches), but I don't want to promise too much now.
Since Posix has such things as signal:
typedef void (*sig_t) (int); sig_t signal(int sig, sig_t func);
to make a Pascal interface to this I need to return a procedural type from a function.
GNU Pascal has function pointers (such pointer can be a return value from a function). So literal translation of the above is possible.
Yes, for now, I'd recommend using function pointers (or `var' parameters as, e.g., the signal routines in gpc.pas such as `InstallSignalHandler' do).
Frank