delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/09/29/04:08:31

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
content-class: urn:content-classes:message
Subject: RE: gcc 3.3.1 problem
MIME-Version: 1.0
Date: Mon, 29 Sep 2003 10:05:39 +0200
Message-ID: <F0D7281DAB048B438E8F5EC4ECEFBDDC174EA9@esmail.elsag.de>
X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
From: =?iso-8859-1?Q?J=F6rg_Schaible?= <Joerg DOT Schaible AT Elsag-Solutions DOT com>
To: <cygwin AT cygwin DOT com>
Note-from-DJ: This may be spam
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id h8T88Tpr031493

Hi Gerry,

you return a pointer to an object on the stack, that is no longer valid after leaving your function. So any value printed in main is undefined and you can get any result.

Regards,
Jörg

Gerry Reno wrote on Monday, September 29, 2003 9:34 AM:

>   I'm having a problem with gcc 3.3.1.  Here is a sample
> program that demos the problem:
> 
> // test.c
> #include <stdio.h>
> #include <windows.h>
> 
> 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
> mailto: grenoml at@ yahoo dot. com
> (if mail bounces please retry later - spam rapidly fills up mailbox)
> 
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com 

--
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/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019