delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/02/22/10:58:25

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
Subject: Re: Accessing global variables causes segfault
From: David Means <dmeans AT the-means DOT net>
To: cygwin AT cygwin DOT com
In-Reply-To: <000701c2da32$4472f640$3264a8c0@AUSTBMOBILE>
References: <000701c2da32$4472f640$3264a8c0 AT AUSTBMOBILE>
Organization: The-Means.net
Message-Id: <1045929492.11418.3.camel@milo>
Mime-Version: 1.0
Date: 22 Feb 2003 10:58:12 -0500

--=-0vBdqA3F2xDWMTVFK4bO
Content-Type: multipart/alternative; boundary="=-OgMq+WMdemZWKZjm/Gei"


--=-OgMq+WMdemZWKZjm/Gei
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

One problem is that 'myglobal' is a pointer to an int, but the int is
never defined, and hence, you're assigning a value to a pointer that
points no where.

It's very common for things like this to work on one platform, but not
another.

On Sat, 2003-02-22 at 00:21, Steve Baldwin wrote:

> I'm having some (further) issues porting some Unix code to cygwin.  I
> have a
> scenario where there are global variables defined in a shared library,
> and referenced in the executable.  See the example below.  Yes I know
> it's bad coding practice, but I'm hoping to port the code with the least
> amount of re-writing as possible.  It works fine under Unix, but as you
> can see from below, doesn't play well under cygwin.  Is there anything
> I can do - apart from the obvious re-write.
>=20
> Cheers,
>=20
> Steve
>=20
> [cdev]$ cat a.c
> #include <stdio.h>
> #include <stdlib.h>
> extern void fx (void) ;
> extern int myglobal ;
>=20
> int
> main (int argc, char **argv) {
>         myglobal =3D 99 ;
>         fx () ;
> }
> [cdev]$ cat b.c
> #include <stdio.h>
>=20
> int             *myglobal ;
>=20
> void
> fx (void)
> {
>         printf("here i am : myglobal =3D %d\n", myglobal) ;
> }
> [cdev]$ gcc b.c -o libb.dll -shared
> [cdev]$ gcc a.c -o a -L. -lb
> [cdev]$ a
> Segmentation fault (core dumped)
>=20
>=20
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/

--=20
David Means

Different all twisty a of in maze are you, passages little.

--=-OgMq+WMdemZWKZjm/Gei
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; CHARSET=3DUTF-8">
  <META NAME=3D"GENERATOR" CONTENT=3D"GtkHTML/1.1.7">
</HEAD>
<BODY>
One problem is that 'myglobal' is a pointer to an int, but the int is never=
 defined, and hence, you're assigning a value to a pointer that points no w=
here.<BR>
<BR>
It's very common for things like this to work on one platform, but not anot=
her.<BR>
<BR>
On Sat, 2003-02-22 at 00:21, Steve Baldwin wrote:
<BLOCKQUOTE TYPE=3DCITE>
<PRE><FONT COLOR=3D"#050c87" SIZE=3D"3"><I>I'm having some (further) issues=
 porting some Unix code to cygwin.  I
have a
scenario where there are global variables defined in a shared library,
and referenced in the executable.  See the example below.  Yes I know
it's bad coding practice, but I'm hoping to port the code with the least
amount of re-writing as possible.  It works fine under Unix, but as you
can see from below, doesn't play well under cygwin.  Is there anything
I can do - apart from the obvious re-write.

Cheers,

Steve

[cdev]$ cat a.c
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
extern void fx (void) ;
extern int myglobal ;

int
main (int argc, char **argv) {
        myglobal =3D 99 ;
        fx () ;
}
[cdev]$ cat b.c
#include &lt;stdio.h&gt;

int             *myglobal ;

void
fx (void)
{
        printf(&quot;here i am : myglobal =3D %d\n&quot;, myglobal) ;
}
[cdev]$ gcc b.c -o libb.dll -shared
[cdev]$ gcc a.c -o a -L. -lb
[cdev]$ a
Segmentation fault (core dumped)


--
Unsubscribe info:      </FONT><A HREF=3D"http://cygwin.com/ml/#unsubscribe-=
simple"><FONT SIZE=3D"3">http://cygwin.com/ml/#unsubscribe-simple</FONT></A=
>
<FONT COLOR=3D"#050c87" SIZE=3D"3">Bug reporting:         </FONT><A HREF=3D=
"http://cygwin.com/bugs.html"><FONT SIZE=3D"3">http://cygwin.com/bugs.html<=
/FONT></A>
<FONT COLOR=3D"#050c87" SIZE=3D"3">Documentation:         </FONT><A HREF=3D=
"http://cygwin.com/docs.html"><FONT SIZE=3D"3">http://cygwin.com/docs.html<=
/FONT></A>
<FONT COLOR=3D"#050c87" SIZE=3D"3">FAQ:                   </FONT><A HREF=3D=
"http://cygwin.com/faq/"><FONT SIZE=3D"3">http://cygwin.com/faq/</I></FONT>=
</A></PRE>
</BLOCKQUOTE>
<PRE><TABLE CELLSPACING=3D"0" CELLPADDING=3D"0" WIDTH=3D"100%">
<TR>
<TD>
<PRE>--=20
David Means

Different all twisty a of in maze are you, passages little.</PRE>
</TD>
</TR>
</TABLE>
</PRE>
</BODY>
</HTML>

--=-OgMq+WMdemZWKZjm/Gei--

--=-0vBdqA3F2xDWMTVFK4bO
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEABECAAYFAj5XnhMACgkQUd0KwqAz4aojgQCcDxiyA+chojwiy8YwOcjXgwmx
sV4AoIAmhW2qwrNuqPCo8A84Bs9s9lIs
=CCse
-----END PGP SIGNATURE-----

--=-0vBdqA3F2xDWMTVFK4bO--

- Raw text -


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