Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs Date: Mon, 29 Sep 2003 09:32:08 -0400 (EDT) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: Gerry Reno cc: cygwin AT cygwin DOT com Subject: Re: gcc 3.3.1 problem In-Reply-To: <20030929073422.95559.qmail@web14404.mail.yahoo.com> Message-ID: References: <20030929073422 DOT 95559 DOT qmail AT web14404 DOT mail DOT yahoo DOT com> Importance: Normal MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Mon, 29 Sep 2003, Gerry Reno wrote: > I'm having a problem with gcc 3.3.1. Here is a sample program that > demos the problem: > > // test.c > #include > #include > > typedef struct abc { > HANDLE h1; > HANDLE h2; > } XYZ; > > XYZ * somefunc () { > XYZ xyz; > XYZ *ptr = &xyz; > > ptr->h1 = (HANDLE) 99; > ptr->h2 = (HANDLE) 88; > > printf("somefunc: ptr->h1 = %d\n",ptr->h1); > printf("somefunc: ptr->h2 = %d\n",ptr->h2); > > return (ptr); > } > > int main(void) { > XYZ *ptr2; > > ptr2 = somefunc (); > printf("main: ptr2->h1 = %d\n",ptr2->h1); > printf("main: ptr2->h2 = %d\n",ptr2->h2); > > } > ------------------------------ > > -- results -- > somefunc: ptr->h1 = 99 > somefunc: ptr->h2 = 88 > main: ptr2->h1 = 99 > main: ptr2->h2 = 99 > > > And sometimes it will give me really large values for main: ptr2-h2 > like 4043574. > > ---------------------- > Env: > Cygwin 1.5.5 > gcc 3.3.1 > > ===== > Gerry Reno Tsk, tsk, tsk, Gerry, you should really know better than to return a pointer to an automatic variable (a struct, in this case). That's one of the things K&R explicitly warns against. You're lucky it worked at all in the previous versions of gcc. If you want to return a pointer to something from a function, either make it global, or static, or allocate it dynamically. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D. '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "I have since come to realize that being between your mentor and his route to the bathroom is a major career booster." -- Patrick Naughton -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/