Hi!
Again, I have some questions about porting from C to Pascal.
- Is there a GNU-Pascal extension, which allows to implement such thing like a union in C ?
- Is there a FILE* ("Pointer to FILE") compatible type available for GNU-Pascal?
Thanks
Eike Lange
Eike Lange wrote:
Hi!
Again, I have some questions about porting from C to Pascal.
- Is there a GNU-Pascal extension, which allows to implement
such thing like a union in C ?
No... it's standard Pascal. ;-) It's called variant records:
type foo = record case Integer of 1 : ( fields ); 2 : ( fields ); ... end
(There can also be fields before the `case' selector, and the selector can be a field itself (case bar : Integer of), but this has no direct equivalent in C.) The type of the selector can be any ordinal type, i.e. also Boolean, Char or an enum type.
- Is there a FILE* ("Pointer to FILE") compatible type
available for GNU-Pascal?
No. GPC's files are based on fd's, not FILE*'s.
Depending on your needs, there are several possibilities:
Open a C file in Pascal: get the fd with fileno(), then use AssignHandle in Pascal.
Open a Pascal file in C: FileHandle, fdopen().
Or use the fd directly in C (if you don't need things like printf()).
When writing to a file in both languages intermixed, be sure to flush it (Flush in Pascal, fflush() in C). When you want to read in both languages, you're in trouble because both read ahead, so you won't usually get the desired results...
Or use the FILE* only in C and provide appropriate wrappers if there's only a limited number of things one wants to do with it from Pascal...
Frank