GNU Pascal Homepage - gpc - gpc-announce - gpc-de - gpc-doc
Diese Seite auf deutsch

Mail #13867

Back to main page of archive

Previous mail   Next mail   Unformatted/full headers
Overview  10 days   Subject   Date   Thread   Author  

From: Gale Paeper
Subject: type mismatch in argument 2 of `NumToString'
Date: 7 Oct 2006, 17:59:41

Waldek Hebisch wrote:
> 
> Ken G. Brown wrote:
> > Thx a lot for your long explanation of Strings.
> >
> > Here is another one that has me baffled.
> >
> > My code in a procedure:
> >
> > procedure doHeader (pageNum, numPages : Integer);
> >
> > var
> > pageNumStr, numPagesStr : Str255;
> >
> > the call:
> > NumToString(pageNum,pageNumStr);
> >
> > I get compile error:
> > error: type mismatch in argument 2 of `NumToString'
> >
> >
> > In NumberFormatting.p
> > procedure NumToString(theNum: SInt32; var theString: Str255); external name '_NumToString';

You're using the wrong set of Mac OS X Pascal Interfaces here.  Your
cite is from FPC's FPCPInterfaces Mac OS X Pascal Interfaces.  Only
GPC's GPCPInterfaces Mac OS X Pascal Interfaces work correctly for GPC compiling.

> > What do I need to do in this case?
> >
> 
> First, when you ask for help you should post a complete example.

Since this is really a Mac OS X Pascal Interfaces type problem, it would
probably be better to seek help for questions like this on the MacPascal
mailing list instead of this mailing list.  You have a much better
chance of getting faster help with Mac OS X interfacing problems and the
reponders will be tailoring their help to a Mac OS X Pascal context. 
You'll also avoid creating additional problems for yourself when a
non-Mac OS X GPC mailing list responder responds with a correct generic
GPC answer which may not necessarily answer the real GPC and Mac OS X
Pascal interfacing problem you're having difficulties with. 
 
> Secondly, the following "works" for me:
> 
> program foo;
> type Str255 = string(255);
>      SInt32 = integer;
> var
> pageNum : SInt32;
> pageNumStr, numPagesStr : Str255;
> procedure NumToString(theNum: SInt32; var theString: Str255); external name '_NumToString';
> 
> begin
>   NumToString(pageNum,pageNumStr);
> end
> .
> 
> "Works" here means that the linker complains about undefined function
> _NumToString (which is expected since I did not provide that function).
> I use a newer gpc version which fixed some parameter passing problems,
> but I doubt that gpc version matters for your problem
> 
> Third, if you want to call Pascal functions defined in different files,
> then read about units and modules in gpc documentation (external is for
> interfacing with other languages).  OTOH if you want to call foreign
> function then you need correct definition of Str255 (Pascal string is
> probably wrong).

It is a foriegn interface to a Mac OS X exported C routine that expects
a UCSD Pascal string format for the Str255 typed parameter.  The only
place one can find a GPC Str255 compatible type for the parameter is in
the Mac OS X GPCPInterfaces' MacTypes.pas interface file.  In that
interface file Str255 is declared as a record type and is declared
specificly for GPC to give the exact memory footprint as the UCSD Pascal
string[255] type that the Mac OS X routines expect to be passed as
parameters.  (Note: GPC will accept the USCD string syntax but what you
get is a GPC native Extended Pascal string schema based type that is the
same as string(UCSD Pascal string size).)

Since GPC doesn't yet support UCSD Pascal string types, to call Mac OS X
rountines you have to use the fake "string" record types predefined in
the GPCPInterfaces' MacTypes.pas unit.  To assist with working with the
fake "string" record types and GPC's native Extended Pascal string
schema types, a GPCStrings.pas unit is also provided in the
GPCPInterfaces.  GPCStrings provides things like operator overloading
for the relational operators and the string concatenation operator
(i.e., +) and conversion routines to deal with the worst of the pains
involved in working with GPC's native string type and the MacTypes' fake
"string" record types.  GPCStrings isn't a perfect solution and it
doesn't try to handle every possible UCSD Pascal string size - just the
ones declared in MacTypes.pas that are needed in interfacing with Mac OS
X routines.

I'll also mention that when you're code is interfacing with Mac OS X
routines it is best to adopt a naming scheme to help in keeping track of
what type of string thing - GPC's native schema based string or fake
"string" record based string - your working with.  In the
GPCPInterfaces, the naming convention uses is: StrXX is a fake "string"
record type and StringXX is the corresponding native GPC string with the
same maximum character capacity as the fake "string" record type has. 
The StringXX types are declared in the GPCStrings unit's interface.

Gale Paeper
gpaeper@empirenet.com


Previous mail   Next mail   Unformatted/full headers
Overview  10 days   Subject   Date   Thread   Author  


In reply to

Author Subject Date
Waldek Hebisch type mismatch in argument 2 of `NumToString' 7 Oct 2006, 19:40:15

Back to main page of archive


Note: This page contains information that does not originate from the owner of this web site, but from the authors of the mails archived. The owner of this web site is not responsible for the content of such information. Any use of that infomation requires the consent of the respective author.

Where WWW addresses (URLs) in the mails archived are marked as hyperlinks, this is only for the comfort of the reader. The content of the web pages linked to like this does not necessarily reflect the opinion of the owner of this web site or of the authors of the mails archived. The owner of this web site is not responsible for the content of such web pages. Those pages are explicitly not to be considered as part of the content of this page, but merely as references.


This page was created by Crystal 0.999 (Linux 2.4.27/i686).