Re: How are string literals represented internally by compilers?

glen herrmannsfeldt <gah@ugcs.caltech.edu>
Sun, 21 Jun 2009 21:44:02 +0000 (UTC)

          From comp.compilers

Related articles
How are string literals represented internally by compilers? tony@my.net (Tony) (2009-06-19)
Re: How are string literals represented internally by compilers? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2009-06-21)
Re: How are string literals represented internally by compilers? walter@bytecraft.com (Walter Banks) (2009-06-23)
| List of all articles for this month |

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups: comp.compilers
Date: Sun, 21 Jun 2009 21:44:02 +0000 (UTC)
Organization: California Institute of Technology, Pasadena
References: 09-06-068
Keywords: code
Posted-Date: 22 Jun 2009 18:10:48 EDT

Tony <tony@my.net> wrote:
< I don't remember reading about how string literals are represented in any of
< the books I have. Until I go back and scour those for the info (assuming it
< is there), I'll ask here. How are string literals represented internally by
< compilers?


When you say 'internally by compilers', it seems to me that you
mean during compilation.


< I assume that it's probably null-terminated character string for
< C and C++ and some kind of length-prefixed thing for Pascal in a specially
< designated data segment area and then just some sort of pointer for a given
< literal is placed in the code, yes?


Those seem likely for the object code and run time representation
for constants. Internally to the compiler, they are likely in
the representation for the language that the compiler is written in.


I would not be surprised to see C compilers in Pascal, or Pascal
compilers in C, though I don't actually know of any. (I haven't
looked very hard.)


The other question for constants, is whether you combine multiple
instances of the same constant into one. It gets interesting if
it is possible, even accidentally, to modify constants.
(Traditionally fun for Fortran, which usually passes arguments
by reference, even constants. Also, K&R C allows string constants
to be modified, though ANSI removed that feature.)


-- glen


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.