According to Hans Ecke:
I think I was a little bit lazy in my question. Of course I meant: What is the schema of type conversion between the members of the ordinal,real and string type familys. I.e. what happens internally and what does the compiler ...
This is a nontrivial question. The complete answer is the function `convert_for_assignment()' in the GPC source file `gpc-typeck.c'.
When passing parameters, other conversions are made, see the function `convert_arguments()', also in `gpc-typeck.c'.
Just a few general guidelines:
- Strings are truncated, where necessary.
- According to Extended Pascal, char variables may get a string value assigned :-( which results in the assignment of the first character or a space in case of the empty string. (GPC warns about this.;-)
- If you assign a value to a variable of a compatible, but shorter type, *no* run-time checks are currently done to ensure that the result will fit in the variable. This is planned for gpc-2.2.
... if there are lines like
var i:integer; l:longint;
r:real; e:extended; s:string(255); p:pchar;
begin i:=l;
Silently truncated; overflows are not caught.
e:=r;
Works without problem. (`Extended' may also be called `LongReal'.)
p:=s;
This works if you enable extended syntax (*$X+*). Then the pointer will point to the first character in the string; the capacity and the length of the string are ignored. Please not that GPC does *not* (yet!;-) automatically append a `chr ( 0 )' to the string.
end.
Greetings,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [971005] maintainer GNU Pascal [971001] - http://home.pages.de/~gnu-pascal/ [971005]