PhobosWatch: manifest => enum

Janice Caron caron800 at googlemail.com
Sat Dec 29 00:31:26 PST 2007


On 12/28/07, Derek Parnell <derek at psych.ward> wrote:
> On Fri, 28 Dec 2007 22:56:27 +0000, Janice Caron wrote:
>
> > On 12/28/07, Derek Parnell <derek at psych.ward> wrote:
> >> In order to do that, won't the compiler need to have access to all the
> >> source code for the application?
> >
> > No.
>
> Why not?
>
> If what we are talking about is having the compiler detect if some code is
> taking the address of a constant value, doesn't the compiler need to see
> the code that does that? And if that code is in an object file and not a
> source file, then how will the compiler find out that the address is being
> taken?

I was going to answer this, but Walter got there first and answered it
before me. Ho hum. Still, I'll paraphrase.

In file_1:

    const int x = 42;

/could/, if we were applying this logic, compile to an object file in
which zero bytes were reserved for x. Then, in file_2:

    import file_1;
    const int * px = &x;

the object file would contain storage for x, in a segment all by
itself. The clever part is that the /linker/, not the compiler, is
able to remove duplicate segments, so if the same segment occurs in
file_3.obj or file_4.obj, it will only appear in the final .exe once.



More information about the Digitalmars-d mailing list