This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: Support for Pascal strings
- To: Mark Mitchell <mark at codesourcery dot com>
- Subject: Re: PATCH: Support for Pascal strings
- From: Ziemowit Laski <zlaski at apple dot com>
- Date: Wed, 20 Jun 2001 16:35:44 -0700
- Cc: Stan Shebs <shebs at apple dot com>, "Joseph S. Myers" <jsm28 at cam dot ac dot uk>, Zack Weinberg <zackw at stanford dot edu>, Neil Booth <neil at daikokuya dot demon dot co dot uk>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
Hi Mark, Zack, et al,
On Wednesday, June 20, 2001, at 03:21 , Mark Mitchell wrote:
Even though I am normally the most rabid anti-extensionist on this list, I am
sympathetic to this particular extension. I do think that it needs to have
complete semantic documentation, which means answering the questions Joseph
raised about what happens with `const char s[2] = "\pxy"' and such.
Yes, I shall cook up an extend.texi patch and post it here for everyone's
review shortly. BTW, 'const char s[2] = "\pxy"' will not work, but
'const unsigned char s[3] = "\pxy"' or 'const unsigned char s[] = "\pxy"'
will be fine. :)
I do think that we need to get a complete description of the semantics. Basically,
I think the questions boil down to:
- What is the type of "\p..."?
The type is 'const unsigned char[strlen("\p...")]', where \p takes up one character. Pointing to this
literal (in C++) requires a 'const unsigned char *'.
- What is the representation of "\p..."?
A NULL-terminated string, with the first character initialized to contain the number of remaining characters
in the string (excluding NULL itself). So, "\p" would be represented (in hex) as 00 00, "\p0" as 01 30 00, etc.
So, if we have 'const unsigned char foo[] = "\pHello";', then foo[0] == 5, strlen(foo) == 6, and '&foo[1]' gets
you a C-usable (albeit unsigned) string. If someone has a more pithy and elegant way of articulating this, I'd be grateful.
Given that, I should think that the entire change could be done in lex_string.
For the most part, yes (I will definitely get the stuff out of cpplib, as Zack suggested),
but I believe string concatentation is done elsewhere and it must also handle Pascal
strings... :(
--------------------------------------------------------------
Ziemowit Laski Apple Computer, Inc.
zlaski@apple.com 2 Infinite Loop, MS 302-4SN
+1.408.974.6229 Fax .1344 Cupertino, CA 95014-2085