Re: global variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Paridhi,

> I have multiple c files in  my project. How is it
> possible to declare static global variables  that are
> accessible from all these files without passing them
> as arguements??
this is i.e. possible with dlopen and dlsym. All you've to do is to open the
actual "main":
    handle = dlopen(NULL, ...);

and then dlsym the variable you wanne read:
    dlsym(handle, "symbol");

Please note that "dlsym" may not give you the variable you expected to get.
Think that it is possible to define the same *static* variable name twice in
more then one .c file. Thus it may make sence to declare a *non static*
symbol which stores the addresses of your variables (declare a global
variable of structure type which stores all the pointers you need to access
in other .c files).

Another way is to declare those variables as non static (remove the static)
and to import them in all other .c files with *extern*.

I highly recommend you *not* exporting variables. Export functions instead.

// Gerrit

----- Original Message -----
From: paridhi bansal <paridhibansal@yahoo.com>
To: <kernelnewbies@nl.linux.org>; <dharmenderr@cybage.com>
Sent: Saturday, November 23, 2002 10:20 AM
Subject: global variables


> Hi
>
> I have multiple c files in  my project. How is it
> possible to declare static global variables  that are
> accessible from all these files without passing them
> as arguements??
>
> Paridhi
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
>

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux