Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How are string literals represented internally by compilers?

2 views
Skip to first unread message

Tony

unread,
Jun 19, 2009, 11:45:46 PM6/19/09
to
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? 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?
[It's language specific, but for these examples, yes. -John]

glen herrmannsfeldt

unread,
Jun 21, 2009, 5:44:02 PM6/21/09
to
Tony <to...@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

Walter Banks

unread,
Jun 23, 2009, 8:06:59 AM6/23/09
to
glen herrmannsfeldt wrote:

> 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.)

Most of our C compilers are written in Delphi Pascal. It is a long
story of history, string support, sets and typechecking.

Regards,

--
Walter Banks
Byte Craft Limited
http://www.bytecraft.com

0 new messages