This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: missed uninitialised variable warning


On Aug  4, 2003, dewar@gnat.com (Robert Dewar) wrote:

>> void *x = &x;
>> 
>> This must work, and I don't see anything possibly dubious about it.

> but I am not sure I can deduce that this must always work from the
> formal semantics

I don't see anything odd about a generic pointer pointing to a memory
location that happens to be its own address.  If you cast this void*
back to its original type (void**), you can even assign to it:

*(void**)x = some_other_pointer;

and it's required to work correctly, i.e., to assign this other
pointer to x.

Now let's please not talk about whether this is actually useful :-)
It may even turn out to be (circular linked lists come to mind), but I
probably wouldn't recommend this style anyway :-)

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]