| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Pascal strings |
On 12 Oct 93 17:51:07, Steven Pasztor had this to say to Michael Baker:
SP>> Is there any way to get C to work with Pascal style
SP>> strings?
MB> Have the length byte at the start of the string and a nul byte at the
MB> end.
MB> Have conversion functions (or macros) so you can use your Pascal-C
MB> strings in standard library functions.
SP> I've been thinking along those lines too... Conversion wouldn't really
SP> be neccisary. Give C routines the string starting at the second
SP> character, and pascal routines get the string starting from the first.
SP> (size byte) Then all you have to do is call a routine which
SP> recalculates the length byte, or replaces the nul depending on wether
SP> it was altered by a C or Pascal routine. Then all you've got to do is
SP> remember to hand C routines a string starting at the second character
SP> instead of the first. That's where the fun starts! :-)
What you describe here is what I had in mind when I said conversion
functions. Something like:
#include
char * P2Cstr(char * str)
{
str[str[0] + 1] = '\0';
return &str[1];
}
char * C2Pstr(char * str)
{
/* this assumes str is a pointer to Pstr[1]
where Pstr is an array of char */
char * Pstr = str - 1;
Pstr[0] = strlen(str);
return Pstr;
}
Beware, I have not tested this.
Michael.
--- Blue Wave/Max v2.12
* Origin: Computer Connection - Adelaide Aust.(+618) 326 2388 (3:800/809.0)SEEN-BY: 50/99 54/54 99 620/243 622/405 623/630 711/401 409 430 807 808 809 SEEN-BY: 711/932 934 712/623 627 713/888 714/906 800/0 1 2 805 809 812 822 SEEN-BY: 800/828 830 843 846 @PATH: 800/809 1 54/54 99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.