httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <>
Subject Re: [Fwd: Problem 2534]
Date Mon, 03 Aug 1998 23:18:54 GMT

On Mon, 3 Aug 1998, Alexei Kosut wrote:

> On Mon, 3 Aug 1998, Ben Laurie wrote:
> > Dirk-Willem van Gulik wrote:
> > > I believe that according to the ANSI standard (page 91)
> > > if I read it correctly a compiler _may_
> > > 
> > >         char foo[] = "hello";
> > >         char some[] = "one";
> > >         char bar[] = "hello";
> > > 
> > > end up having foo == bar. Or even if you are unlucky
> Waitaminute. If this was *foo and *bar, then I could buy this; it makes
> sense. But foo[] and bar[] are supposed to allocate arrays on the stack
> (six bytes each), and are supposedly writeable. Any compiler that makes
> foo == bar is severely wrong, IMHO. Unless you're allowing your optimizing
> compiler to play with your stack arrangement, and it should only do that
> in this case if it's absofragginglutely sure you're not modifying either
> foo or bar. Which isn't a case covered by the ANSI/ISO spec. 

Actually I believe that ANSI requires all globals to have unique addresses,
so they couldn't be combined.

If the declarations were:

    static const char *foo = "hello";
    static const char *bar = "hello";

The compiler could combine the two.  They're read-only.  i.e. foo == bar,
but &foo != &bar.

Few compilers do this, and the ones that do usually only do it when you
explicitly ask for it.  However for compatibility with broken programs
that do things like:

    char *foo = "hello";

and then modify foo[i]... this combining also an option.  gcc
-Wwriteable-strings (or something like that) turns on warnings so folks
can find such problems in their programs (apache isn't clean under this
warning, I forget what the worst problem is).


View raw message