* Accessing static variable from outside
@ 2007-06-16 2:08 Rajat Jain
2007-06-16 3:09 ` Adrian Bunk
2007-06-16 16:36 ` tejas khatiwala
0 siblings, 2 replies; 4+ messages in thread
From: Rajat Jain @ 2007-06-16 2:08 UTC (permalink / raw)
To: Linux Newbies, newbie
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Accessing static variable from outside
2007-06-16 2:08 Accessing static variable from outside Rajat Jain
@ 2007-06-16 3:09 ` Adrian Bunk
2007-06-16 16:36 ` tejas khatiwala
1 sibling, 0 replies; 4+ messages in thread
From: Adrian Bunk @ 2007-06-16 3:09 UTC (permalink / raw)
To: Rajat Jain; +Cc: Linux Newbies, newbie
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Accessing static variable from outside
2007-06-16 2:08 Accessing static variable from outside Rajat Jain
2007-06-16 3:09 ` Adrian Bunk
@ 2007-06-16 16:36 ` tejas khatiwala
2007-06-17 10:20 ` Erik Mouw
1 sibling, 1 reply; 4+ messages in thread
From: tejas khatiwala @ 2007-06-16 16:36 UTC (permalink / raw)
To: Rajat Jain; +Cc: Linux Newbies, newbie
[-- Attachment #1: Type: text/plain, Size: 873 bytes --]
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 ecartis@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>
[-- Attachment #2: Type: text/html, Size: 1344 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Accessing static variable from outside
2007-06-16 16:36 ` tejas khatiwala
@ 2007-06-17 10:20 ` Erik Mouw
0 siblings, 0 replies; 4+ messages in thread
From: Erik Mouw @ 2007-06-17 10:20 UTC (permalink / raw)
To: tejas khatiwala; +Cc: Rajat Jain, Linux Newbies, newbie
-----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+74h5QCgiH51
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-06-17 10:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-16 2:08 Accessing static variable from outside Rajat Jain
2007-06-16 3:09 ` Adrian Bunk
2007-06-16 16:36 ` tejas khatiwala
2007-06-17 10:20 ` Erik Mouw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox