On 25 May 2005 at 13:28, Pascal Viandier wrote:
Hi,
I am porting SUN Pascal code to GNU Pascal. When I first read the GNU Pascal documentation (the pdf manual), I was pleased to see that GNU Pascal strings were in fact records with the length and the string text: this map perfectly with SUN Pascal VARYING[..] OF CHAR we use, since it is a record with 4 bytes for the length and an array of char. So, no porting problem...
But now, I see in gdb that a GNU Pascal variable of type STRING(20) is not anymore as in the documentation: There are two fields of type Cardinal holding the capacity and the actual length of the string, plus the array of char. Since the low-level part of our applications are written in C, many of them get Pascal strings as parameters and map them on C struct's. They rely on the SUN Pascal type to find the length and the text. Is there a way (a compiler option?) to have the STRING type map as explained in the documentation, or will have I to modify all the C routines (a big task)?
It is always dangerous to rely on the internal representation of strings. What happens when it changes again? (and I am assuming that it will change when GPC gets ansistrings, UCSD style strings, and such). Be that as it may, you may wish to declare a Pascal data type that maps into your C struct, and then have a Pascal routine that converts a GPC string into that data type, ready for passing to the C routines. When the internal structure of GPC strings changes, all you will need to amend is your Pascal conversion routine.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/