Hi, I'm having a problem where strings seem to get corrupted when they are returned as a CString from a module.
It is certainly possible that this is a problem on my end as I may be illegally modifying strings in someway, as I am mixing EP string() type variables and CStrings, as well as using {$x+} features. Is there a good guide on how to use/convert the different string types? I know this code used to work with older versions of gpc -- trying to move my Pascal code from OS/2 to Linux (more on that in next message) caused me to find this.
Anyways here is a sample run of the code included below:
Main Loop: Hello there. In Module: Hello there. In Module(2): Hello there. After Module: x)@xY@ere.
I replaced the high ASCII with an x to avoid mailer mangling.
I'm using the latest version of gpc (compiled for gcc-2.95) available as a Debian package. It claims to be 19990610, but someone said that the latest snapshot misreports? -- so I think it is the latest version. If I'm wrong, sorry.
The code follows below: foo.pas:
Module FOO Interface;
Export FOO = (twine);
function twine(foobar : CString): CString;
end. { Interface }
Module FOO Implementation;
type String25 = String(25); function twine; {$x+} var local : String25;
begin writeln('In Module: ', foobar); writestr(local, foobar, chr(0)); writeln('In Module(2): ', local); twine := local; end; { twine }
end. { FOO }
test.pas: program test(input, output);
import foo;
var foobaz : Cstring;
begin {$x+} foobaz := "Hello there."; writeln('Main Loop: ', foobaz); writeln('After Module: ', twine(foobaz)); end.
Thanks, -Kevin