It is currently Sat, 04 Feb 2023 11:21:14 GMT



 
Author Message
 global variable in shared library.
Hello,

  I have encounted a problem that, when a global variable is declared in shared
library, if the application using that library has the same variable name, but
with different size ( for example,  in library, I declared 'char myname[256]'
and in the application, I delcared 'char myname[128]'). The application _may_
crash during termination.

 What is the rule of using global variable in a shared library? I was doing
mostly Win32 application and it is not a problem as all as the global variable
in a DLL is tight in the DLL address space only. It is not visisble to the
process unless you explicitly put into a shared memory region.

TIA.

- Wong



 Mon, 21 Apr 2003 12:00:52 GMT   
 global variable in shared library.
Wong Ka Chun (eewk...@engsvr.ust.hk) wrote:

Shouldn't you declare the variable as

extern char *myname;
or
extern char myname[n];  /* n can be anything you want */

I think you just declare a local variable, so when you try to access memory
beyond the 128th byte, you corrupt it.

--
Erik Hensema (e...@hensema.net)
Please note that my From: field is spamtrapped.



 Mon, 21 Apr 2003 19:00:50 GMT   
 
   [ 2 post ] 

Similar Threads

1. global variable with shared library

2. Global variables inside shared library on Solaris

3. Visibility of global variables in shared libraries

4. global variable in shared library?

5. Singleton global variable in a shared library

6. Shared libraries and global variables

7. Problems with shared libraries and external global variables

8. Global data sharing in shared libraries

9. Shared variable between main() and loaded shared library - dlopen()

10. shared variables in shared libraries


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software