Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!bu.edu!purdue!sage.cc.purdue.edu!ar4 From: ar4@sage.cc.purdue.edu (Piper Keairnes) Newsgroups: comp.sys.mac.programmer Subject: Re: ThinkC prototypes and Str255 args Message-ID: <4449@sage.cc.purdue.edu> Date: 15 Sep 90 20:35:32 GMT References: <1990Sep15.154434.17307@midway.uchicago.edu> Organization: Purdue University Lines: 38 fri0@quads.uchicago.edu (Christian E. Fritze) writes: >I'd like to be able to call functions which expect arguments of the type Str255 >with a string I build on the fly. If I try to pass a string to a function like >SomeFunction("\pHere's my string"); There is one problem... C passes arguments by value. So, when you make a call to some procedure that expects a Str255, it is expecting the entire string array. When you make a call such as the one above, C is simply passing a pointer to that string. The workaround: Make and use a procedure like the one below... Call like you want to... SomeFunction2("\pHere's my string"); SomeFunction2(s) char *s; { int i; Str255 theString; /* you may want to have some error detection */ theString[0] = s[0]; /* copy length byte */ for (i=1; i<=theString[0]; i++) /* copy rest of string */ theString[i] = s[i]; SomeFunction(theString); } All that this function does is takes your string literal and stores it in a variable of type Str255 then calls the intended function with that variable. You can do this yourself in your code, or make a small function like above to handle the interface and keep you code a little cleaner. This is what we get for programming in C on a machine that was written in Pascal! Please don't flame my code, I wrote it on the fly while reading news. ----- Piper Keairnes - Computer Science ** Purdue University Computing Center ** INTERNET: ar4@sage.cc.purdue.edu ** Unisys Corporation Co-op Student ** BITNET: xar4@purccvm.bitnet ** Macintosh Programmer/ Specialist **