Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!europa.asd.contel.com!gatech!bloom-beacon!eru!hagbard!sunic!chalmers.se!appli!niklas From: niklas@appli.se (Niklas Hallqvist) Newsgroups: comp.lang.c++ Subject: Re: references as class member variables Message-ID: <1391@appli.se> Date: 3 Jun 91 10:31:52 GMT References: <9105300036.aa15925@ics.uci.edu> Organization: Applitron Datasystem AB, GOTHENBURG, SWEDEN Lines: 41 schmidt@crimee.ics.uci.edu (Douglas C. Schmidt) writes: >Hi, > I'm curious... Does anyone know what the "proper" output for >the following program should be (or is it perhaps officially undefined?) >g++ prints 10, 11, whereas cfront 2.0 prints 11, 11. >-------------------------------------- >struct Foo >{ > int &r; > Foo (int s): r (s) { } >}; >extern "C" void printf (const char *, ...); >main () >{ > Foo f (10); > Foo g (11); > printf ("%d, %d\n", f.r, g.r); >} >---------------------------------------- I don't have my ARM with me, but as I recall it, this is officially undefined. You are aliasing a parameter passed by value, which is risky, at least. If the parameter is passed in a register, the compiler is allowed to make a temporary which is then aliased. If it's passed in a stack slot, the stack slot will be aliased. This stack slot could of course be reused when it goes out of scope. If this is incorrect, please flame me ;-> Niklas -- Niklas Hallqvist Phone: +46-(0)31-40 75 00 Applitron Datasystem Fax: +46-(0)31-83 39 50 Molndalsvagen 95 Email: niklas@appli.se S-412 63 GOTEBORG, Sweden mcsun!sunic!chalmers!appli!niklas