[fpc-pascal]What exactly is Pchar good for ?
Martyn Ranyard
ranyardm at lineone.net
Thu Jul 18 21:16:12 CEST 2002
On Thursday 18 July 2002 18:28, A.J. Venter wrote:
> Ok,
> I am getting more annoyed by the day with these PChars. Half the packages
> use them, and I they don't seem to have any REAL virtue at all. They still
> have the 256 character limit (as I found out today when a program suddenly
> broke) they cannot be easilly typecast to strings and back and who know how
> many other idiotics in there.
(bear in mind I am talking from a TP/BP/Delphi standpoint - any differences
are unlikely in this respect, but if there are then I expect someone will
correct me)
This doesn't seem right - a PChar is just a pointer to a character, where the
string follows on flat-form in memory, with a #0 at the end. Is this what's
going wrong? Have you forgotton to add the null character at the end?
> I use ansistrings for almost everything, but here I am creating a mysql
> backed CGI when suddenly stuff starts mysteriously breaking, and I discover
> (after nearly and hour of hunting through over 2000 lines of code) that
> even though my ansistring CGI input works fine, any remotely big textarea
> becomes to big to fit into a pchar, which is what I need to typecast (and
> whoever heard of needing 4 different statements to typecase one string type
> to another ?) my inputs to in order to do a mysql_query.
Are you sure it's not being typecast outside of your code and when passed as
a pchar?
> Ok, so besides the rant, can somebody please explain to me just what it is
> that makes pchars popular, or even allows their continued existence ? Is
> there something I missed ?
In the windows world, where C rules supreme, strings are simply placed into
char arrays with a null character at the end. That's why they're so popular.
I would have thought that the code behind ansistrings are pchars, but I may
be wrong.
> Or is just a case of C having pathetic string handling and pchar being a
> pathetic string handler for pascal because it is designed ot be C
> compatible ?
Yes, as most languages/APIs interoperate with C, they expect certain things
as c strings, which pascals pchars are completely compatible with. Like I
say, I am unaware of any length limit - there certainly isn't one in the
Borland compilers.
> /me bangs head against table repeatedly.
>
> Ciao
> A.J.
Martyn Ranyard
Free Software Advocate
email: ranyardm at lineone.net
jabber: joran at amessage.de
msn: ranyardm at hotmail.com
More information about the fpc-pascal
mailing list