[comp.sys.mac.programmer] CtoPstr

rg2c+@andrew.cmu.edu (Robert Nelson Gasch) (12/13/90)

This is probably really stupid, but I can't figure out what I'm doing
wrong. It's getting sort of frustrating.

Could anybody out there please tell me what exactly the function
prototype for CtoPstr looks like? When I call it using

    CtoPstr (&temp);

where temp is of type Str255. I get the error "Call does not match
function prototype" or something of that sort.

Thanx
--> Rob

hairston@henry.ece.cmu.edu (David Hairston) (12/13/90)

[rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes:]
[] Could anybody out there please tell me what exactly the function
[] prototype for CtoPstr looks like? When I call it using
[]
[]     CtoPstr (&temp);
[]
[] where temp is of type Str255. I get the error "Call does not match
[] function prototype" or something of that sort.

hmmm ...

the THINK C 4.0 manual gives the prototype as:
char *CtoPstr(char *s);

assuming you've declared:
Str255 temp;

try:

(void) CtoPstr((char *) temp);

btw, the prototypes are in the various header files somewhere in your
development tree.  in particular, CtoPstr should be in
Mac #includes:pascal.h.  there's a neat trick that'll let you jump
to any included file from your Think C project: option-click in the
title bar to get a menu of included files.  this also works on a file
by file basis (i.e. option click on the title bar of the source file
window).  ummmm, this is all in the manual.

hope this helps ...

  -dave-  
hairston@henry.ece.cmu.edu

jlee4@lion.uwaterloo.ca (Johnny Lee) (12/14/90)

In article <18153@shlump.nac.dec.com> vandevyver@cuvee.enet.dec.com writes:
>
>>[rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes:]
>>[] Could anybody out there please tell me what exactly the function
>>[] prototype for CtoPstr looks like? When I call it using
>>[]
>>[]     CtoPstr (&temp);
>>[]
>>[] where temp is of type Str255. I get the error "Call does not match
>
>just declare the string as a normal c string, but, make it big enough (at leat
>1 bigger than needed.

Huh?! He doesn't need to change the type of temp. If you've got a C string
in temp, then all you need to do is cast it to a char *
(since I expect the prototype is CtoPStr(char *);, actually
I think it's "char *CtoPStr(char *);" ).

You just need to have enough room for the C string, since the Pascal
string will use the same amount of room as the C string.

Johnny

vandevyver@cuvee.enet.dec.com (12/14/90)

In article <HAIRSTON.90Dec12230542@henry.ece.cmu.edu>, hairston@henry.ece.cmu.edu (David Hairston) writes...
>[rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes:]
>[] Could anybody out there please tell me what exactly the function
>[] prototype for CtoPstr looks like? When I call it using
>[]
>[]     CtoPstr (&temp);
>[]
>[] where temp is of type Str255. I get the error "Call does not match
>[] function prototype" or something of that sort.

just declare the string as a normal c string, but, make it big enough (at leat
1 bigger than needed.

And beware : CtoPstr will modify the ORIGINAL string, so you cannot call this
function twice without re-initialisation!

Good luck,

Luc Van de Vyver 

u2zj@vax5.cit.cornell.edu (Stanton Loh) (12/14/90)

In article <MbNepFS00Uh_M4CG51@andrew.cmu.edu>,
rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes:
> This is probably really stupid, but I can't figure out what I'm doing
> wrong. It's getting sort of frustrating.
>
> Could anybody out there please tell me what exactly the function
> prototype for CtoPstr looks like? When I call it using
>
>     CtoPstr (&temp);
>
> where temp is of type Str255. I get the error "Call does not match
> function prototype" or something of that sort.
>
> Thanx
> --> Rob

The prototype is:

char *CtoPstr(char *);

but the compiler complains because Str255 is a pointer to unsigned char.

-Stanton

urlichs@smurf.sub.org (Matthias Urlichs) (12/15/90)

In comp.sys.mac.programmer, article <18153@shlump.nac.dec.com>,
  vandevyver@cuvee.enet.dec.com writes:
< 
< [ talking about CtoPstr ]
<
< just declare the string as a normal c string, but, make it big enough (at leat
< 1 bigger than needed.
< 
Actually, no. The C string will have a zero byte at the end and the Pascal
string has a length byte in front -> no size difference.

< And beware : CtoPstr will modify the ORIGINAL string, so you cannot call this
< function twice without re-initialisation!
< 
In other words, _never_ use it on constants, as in 
	CtoPstr("xyzzy")

That code will work exactly once.

It might also not be a good idea to use the UPPERCASE names for some toolbox
routines (which call CtoPstr internally, make the toolbox call, and then call
PtoCstr on the string again to pretend that nothing has happened).
Performance can only get worse when you do things like that; besides,
modifying your code resources (if you let the compiler put string constants
in code) is frowned upon, as it may break in the future.

-- 
Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de     /(o\
Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(0700-2330)   \o)/

Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) (12/16/90)

In article <1990Dec13.195336.15562@watdragon.waterloo.edu>
jlee4@lion.uwaterloo.ca (Johnny Lee), responding to 
vandevyver@cuvee.enet.dec.com,
writes:
   
> Huh?! He doesn't need to change the type of temp. If you've got 
> a C string in temp, then all you need to do is cast it to a char 
> * (since I expect the prototype is CtoPStr(char *);, actually 
> I think it's "char *CtoPStr(char *);" ). 

It is char *CtoPstr(char *) but a Str255 is typedef unsigned char Str255[256];
 
so you will need a cast from char * to unsigned char *. 
 

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!56.12!Chris.Gehlker
Internet: Chris.Gehlker@p12.f56.n114.z1.fidonet.org

Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) (12/16/90)

In article <MbNepFS00Uh_M4CG51@andrew.cmu.edu>
rg2c+@andrew.cmu.edu (Robert Nelson Gasch) asks:

RNG> Could anybody out there please tell me what exactly the function 
RNG> prototype for CtoPstr looks like? When I call it using 
RNG>  CtoPstr (&temp); 
RNG> where temp is of type Str255. I get the error "Call does not 
RNG> match function prototype" or something of that sort. 

Your problem is that a Str255 is an unsigned char * but CtoPstr is
char * CtoPstr(char *) so you need to cast temp to char *. 
 

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!56.12!Chris.Gehlker
Internet: Chris.Gehlker@p12.f56.n114.z1.fidonet.org

murat@farcomp.UUCP (Murat Konar) (12/17/90)

In article <MbNepFS00Uh_M4CG51@andrew.cmu.edu> rg2c+@andrew.cmu.edu (Robert Nelson Gasch) writes:
>This is probably really stupid, but I can't figure out what I'm doing
>prototype for CtoPstr looks like? When I call it using
>
>    CtoPstr (&temp);
>
>where temp is of type Str255. I get the error "Call does not match
>function prototype" or something of that sort.
>

Try CToPStr((StringPtr)&temp);



-- 
____________________________________________________________________
Have a day. :^|             
Murat N. Konar	
murat@farcomp.UUCP             -or-          farcomp!murat@apple.com