Accessing static variable from outside
Accessing static variable from outside
am 16.06.2007 04:08:07 von Rajat Jain
Hi,
I understand that this is off-topic, but still if some one has any ideas ...
I have a global variable that is defined static in an object file (say
1.o). Now I want to be able to get the value of this variable in
ANOTHER object file (say 2.o) without changing the source of 1.c.
Any ideas, anyone? I know that as per C, this is not possible. But may
be some clever hack?
Thanks,
Rajat
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Re: Accessing static variable from outside
am 16.06.2007 05:09:26 von Adrian Bunk
On Sat, Jun 16, 2007 at 07:38:07AM +0530, Rajat Jain wrote:
> Hi,
>
> I understand that this is off-topic, but still if some one has any ideas
> ...
>
> I have a global variable that is defined static in an object file (say
> 1.o). Now I want to be able to get the value of this variable in
> ANOTHER object file (say 2.o) without changing the source of 1.c.
>
> Any ideas, anyone? I know that as per C, this is not possible. But may
> be some clever hack?
Depending on how the variable gets used the compiler might even
completely optimize it away.
> Thanks,
>
> Rajat
cu
Adrian
--
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Re: Accessing static variable from outside
am 16.06.2007 18:36:43 von tejas khatiwala
------=_Part_57925_1776847.1182011803952
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
AFAIK one way to be able to access a static variable is using dynamic
linking lodader. u can read man pages of dlopen() and family. and here is
example of its usage http://www.slimy.com/~jleonard/src/dlopen.html
/tejas
On 6/15/07, Rajat Jain wrote:
>
> Hi,
>
> I understand that this is off-topic, but still if some one has any ideas
> ...
>
> I have a global variable that is defined static in an object file (say
> 1.o). Now I want to be able to get the value of this variable in
> ANOTHER object file (say 2.o) without changing the source of 1.c.
>
> Any ideas, anyone? I know that as per C, this is not possible. But may
> be some clever hack?
>
> Thanks,
>
> Rajat
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>
------=_Part_57925_1776847.1182011803952
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
AFAIK one way to be able to access a static variable is using dynamic linking lodader. u can read man pages of dlopen() and family. and here is example of its usage
http://www.slimy.com/~jleonard/src/dlopen.html
/tejas
On 6/15/07, Rajat Jain <rajat.noida.india@gmail.com
> wrote:Hi,
I understand that this is off-topic, but still if some one has any ideas ...
I have a global variable that is defined static in an object file (say
1.o). Now I want to be able to get the value of this variable in
ANOTHER object file (say 2.o) without changing the source of 1.c.
Any ideas, anyone? I know that as per C, this is not possible. But may
be some clever hack?
Thanks,
Rajat
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to
------=_Part_57925_1776847.1182011803952--
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Accessing static variable from outside
am 17.06.2007 12:20:24 von Erik Mouw
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
A: No.
Q: Should I leave quotations after my reply?
On Sat, Jun 16, 2007 at 11:36:43AM -0500, tejas khatiwala wrote:
> AFAIK one way to be able to access a static variable is using dynamic
> linking lodader. u can read man pages of dlopen() and family. and here is
> example of its usage http://www.slimy.com/~jleonard/src/dlopen.html
The example doesn't apply:
- - dlopen() is a userspace function and can't be used in kernel
- - dynamic linking can only be used to link exported (i.e. non-static)
symbols
Like Adrian Bunk already explained: there are dirty tricks to get the
address of a static variable, but they will all fail when the compiler
decides to optimise the variable away (which it is completely free to
do because the "static" keyword *guarantees* that the variable will not
be used outside that particular compilation unit).
Erik
- --
They're all fools. Don't worry. Darwin may be slow, but he'll
eventually get them. -- Matthew Lammers in alt.sysadmin.recovery
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGdQrn/PlVHJtIto0RAsWkAJ0Qk9txqXYxwLMEeioj8z4T+74h5QCg iH51
7yl9an3I/1EPWWkw4eFqOrA=
=bEkd
-----END PGP SIGNATURE-----
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs