Mac OS X 10.4.8, gpc 35u2
This is driving me crazy. Why does this snippet give a compile error in the function declaration? error: syntax error before `('
program PrtTst2;
uses GPCStringsAll;
// from the gpc.pdf manual this is the way a function should look // // function function_identifier (parameter list): result type ; // declaration part // begin // statement part // end;
function fixDateYear(thisDate : String(255)) : String(255); begin end;
begin {main} end.
Thx for any help, Ken
Ken G. Brown wrote:
Mac OS X 10.4.8, gpc 35u2
This is driving me crazy. Why does this snippet give a compile error in the function declaration? error: syntax error before `('
program PrtTst2;
uses GPCStringsAll;
// from the gpc.pdf manual this is the way a function should look // // function function_identifier (parameter list): result type ; // declaration part // begin // statement part // end;
function fixDateYear(thisDate : String(255)) : String(255); begin end;
begin {main} end.
For function parameters and and return type Pascal allows only type _name_. Change your program to:
program PrtTst2;
type String255 = String(255);
function fixDateYear(thisDate : String255) : String255; begin fixDateYear := thisDate end;
begin {main} end.
and gpc will accept it.
Waldek Hebisch wrote:
Ken G. Brown wrote:
Mac OS X 10.4.8, gpc 35u2
This is driving me crazy. Why does this snippet give a compile error in the function declaration? error: syntax error before `('
String is an undiscriminated schema type in Extended Pascal. Discriminatining a schema with with actual discriminate value(s), e.g., string(255); is a type-denoter according to Extended Pascal's type requirements. The Extended Pascal rules for parameter-forms (which is a formal parameter type-identifier in Standard Pascal), do not allow type-denoters in parameter-forms. The rules do allow schema-names (which is a [interface-identifier.]schema-identifier). String is a schema-identifier; but string(255) is not an identifier.
If you use the schema-identifier, string, for the parameter-form, Extended Pascal's type compatibility rules allow actual parameters of one of the type classifications of char, fixed-string (e.g., packed array [1..10] of char), and variable-string (e.g., string(50)). Thus after fixing your example:
aStr := fixDateYear('1'); aStr := fixDateYear('0123456789'); aStr := fixDateYear( aVariableString );
would all meet the parameter passing rules.
The type of thisDate is dynamic. For value parameters with a parameter-form of string like your example, paramter's type is a discrimated string type with a capacity equal to the length of the actual parameter and the length og the string is set to the length of the actual parameter.
Therefore, for the first call thisDate gets the type string( 1 ) and has a length of 1; for the scecond call thisDate gets the type string( 10 ) and has a length of 10; and for the last call thisDate gets the type string( Length( aVariableString ) ) and has a length of Length( aVariableString ).
It is a little bit different for var parameters with a parameter-form of string. Since variable-access actual paramters are allowed, only the third call would be legal. For that call with a var parameter, the formal parameter-identifier has the type of string( aVariableString.capacity ) and a length of Length( aVariableString ).
program PrtTst2;
uses GPCStringsAll;
// from the gpc.pdf manual this is the way a function should look // // function function_identifier (parameter list): result type ; // declaration part // begin // statement part // end;
function fixDateYear(thisDate : String(255)) : String(255); begin end;
begin {main} end.
For function parameters and and return type Pascal allows only type _name_. Change your program to:
Since GPC supports Extended Pascal, it is a little more than type-name for formal parameters. In addition to type-name, schema-name and type-inquiry (i.e., type of) are legal where string type parameters are concerned.
program PrtTst2;
type String255 = String(255);
function fixDateYear(thisDate : String255) : String255; begin fixDateYear := thisDate end;
begin {main} end.
and gpc will accept it.
I see you fixed the other error too.
Another alternative that GPC accepts:
function fixDateYear(thisDate : String) : String;
I'll note for UCSD Pascal string porting compatibility reasons, GPC will treat "string" in some cases as if it were a type-identifier for a string(255). You'll general get a compiler warning when it treats "string" like that.
A strict enforcement of function result-type rule would disallow either String(255) or String since the return-typre is strictly supposed to be just type-name (type-identifier) which neither String(255), a type-denoter, or String, a schema-name(schema-identifier) are.
begin
I'll also mention, that once you fix the String(255)'s, you'll get another GPC error because you haven't tried to assign anything to fixDateYear. The rules reuie there be at least one threat (e.g., assignment) to the function-identifier within the body of the function. GPC is one of the few Pascal compilers that enforce that rule.
end;
begin {main} end.
Gale Paeper gpaeper@empirnet.com