Hi,
I have a problem in that I need to compile a program where a function is declared as type string.
Here is a sample
program test(input,output); function getname: string; begin getname := 'somestring'; end; begin end.
The compiler aborts with parse error before 'String'
If I declare the function as char it compiles.
How do I get this to compile?
Please reply directly as I have just subscribed to the List.
I am using gpc version 2.0
Thanks in Anticipation
Andrew Cameron
Andrew Cameron wrote:
function getname: string; begin getname := 'somestring'; end; [...] I am using gpc version 2.0
Please upgrade to a more recent version such as gpc-19980830; see ftp://agnes.dida.physik.uni-essen.de/gnu-pascal/beta/.
The error message comes from GPC's strings not being limited to a maximum of 255 chars. On a 32-bit platform, they can be up to 4GB long. For this reason, GPC cannot determine a reasonable default length for strings being returned as function results.
While gpc-19980830 will compile your program (defaulting to 255, with a warning), it is better to avoid the problem by something like this:
type mystring = string (255);
function getname: mystring; begin getname := 'somestring'; end;
Hope this helps,
Peter