Adriaan van Os wrote:
Another problem, also reported on the macpascal mailing list and reproduced by the following program:
[G5:gcc/p/test] adriaan% cat avo12.pas program avo12;
type Str255 = record sLength: Byte; sChars: packed array[1..255] of char; end;
function StringToStr255 ( const s: String ) = Result : Str255; begin Result.sLength := Min( Length( s ), 255 ); if Result.sLength > 0 then begin Result.sChars[1..Result.sLength] := s[1..Result.sLength]; end; end;
procedure DrawString1( const s: Str255); external name 'DrawString'; procedure DrawString2( protected var s: Str255); external name 'DrawString';
begin DrawString1( StringToStr255( 'Hello')); {OK} DrawString2( StringToStr255( 'Hello')) {Error: reference expected, value given} end.
[G5:gcc/p/test] adriaan% gpc avo12.pas avo12.pas: In main program: avo12.pas:19: error: reference expected, value given
In gpc-20030830, this was no problem,
Then it was a bug in 20030830. `protected var' clearly requires a reference.
but now it is no longer allowed, which is quite inconvenient. In the GPC interfaces for Mac OS X, we use the external declaration form with a "protected var" because (according to the gc docs) the "const" declaration form doesn't guarantuee that the parameter is passed by reference, which is an ABI requirement.
In general it doesn't. This particular type is currently passed by reference (as `const'), so for a temporary work-around (until GPC has short strings) it may be acceptable.
But actually I think you have a problem here. If you need a reference in the call, and only have a string value, you usually need a variable to assign it to. I know this might be quite uncomfortable to do in each call, but anything else seems rather fragile. You might want to consider writing wrapper routines (that accept string values and pass references).
Frank