Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
From: levi@localhost.nc3a.nato.int
Subject: a string question
Date: 11 Jul 2001, 12:31:52
Adam Naumowicz wrote: > On Wed, 11 Jul 2001, Marco van de Voort wrote: > > >>>> This is your problem. Use 'New' instead of 'getmem' - i.e., >>>> New (a, 3 * sizeof (NameStr)); >>>> or >>>> New (a, sizeof (shortarray)); >>>> or better still, just "New (a);" >>> >>> Thanks for your answers. >>> But I want my sources to stay BP/Delphi compatible... >>> I still don't know what is wrong with the getmem call. >>> Maybe I should try this example with a newer compiler as Maurice says >>> it works fine for him. It worked fine for me with BP, Delphi and FPC, but >>> all those handle strings in somewhat different manner than GPC. >>> Why is new better than getmem in this example ? >> >> Because automatic initialisation is run that way. >> >> This also goes for FPC and Delphi, not only GPC. Probably you were just >> lucky, or the compiler was able to detect what you meant. >> >> Or Delphi and FPC used shortstring for this, and GPC schemata. But if you'd >> use automated types in FPC/Delphi (like ansistring/dynamic arrays) you could >> run into these problems too. NEW is really better. > > Thanks. I read the > http://agnes.dida.physik.uni-essen.de/~gnu-pascal/gpc_37.html#SEC37 as > the Chief suggested me to do, and now I can see what is the reason of such > behaviour. But still I would like to allocate only a part of the array > (to simulate a dynamic array - the piece of code I'm working with is from > an old non-OOP Pascal version). I also cannot pass size to standard NEW > call (at least in BP) ... Then declare shortarry as an array of string pointers instead of an array of strings, and allocate with new the number of strings you really need. I have done this many times in the past (for large matrices). Still now I prefer the dynamic arrays possible with the schemata of gpc and send BP to hell ... Maurice
Previous mail
Next mail
Unformatted/full headers
Overview 10 days
Subject
Date
Thread
Author
| Author | Subject | Date |
|---|---|---|
| Adam Naumowicz | a string question | 11 Jul 2001, 12:23:25 |
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).