This is the mail archive of the mailing list for the Cygwin 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: Accessing global variables causes segfault

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.



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

main (int argc, char **argv) {
        myglobal = 99 ;
        fx () ;
[cdev]$ cat b.c
#include <stdio.h>

int             *myglobal ;

fx (void)
        printf("here i am : myglobal = %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)

Unsubscribe info:
Bug reporting:
David Means

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

Attachment: signature.asc
Description: This is a digitally signed message part

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