Setting the address of a variable 
Author Message
 Setting the address of a variable

I have two libraries, in one a structure is defined as

(library 1)
mystruct_t    myinstance;

and I pass the address of that structure to another shared library
(from library1 to library2)
mystruct_t *exported_instance;

and want to set
(library2)
mystruct_t    imported_instance;

such that imported_instance and myinstance both use the same address (and
are both updated as one var).

1. is this possible?
2. what is the dereference syntax if it is possible?



Fri, 25 Aug 2000 03:00:00 GMT  
 Setting the address of a variable


Quote:

>I have two libraries, in one a structure is defined as

>(library 1)
>mystruct_t    myinstance;

>and I pass the address of that structure to another shared library
>(from library1 to library2)
>mystruct_t *exported_instance;

>and want to set
>(library2)
>mystruct_t    imported_instance;

>such that imported_instance and myinstance both use the same address (and
>are both updated as one var).

Unfortunately, you are asking about matters that are beyond the C language.

Quote:
>1. is this possible?

In C, linking is achieved across multiple translation units by writing
declarations of the same identifier with external linkage in each
translation unit, and a single definition in exactly one place.
All declarations must have a compatible type, of course.

The C language doesn't define the behavior and properties of
platform-dependent extensions such as shared libraries.

What you are asking for is the aliasing of two objects using different names,
like a fortran EQUIVALENCE, which is certainly not possible with semantics of
the C language. Each object in C has at most one declared name.

If your program must use dynamically loaded objects, you should make few
assumptions about the facilities that are available. The least you can get
away with is probably to assume that you can attach some dynamic object to
your program and then search its symbol space by name.  Use this search to
locate an entry point ``init'' function within that object, and call that
function, passing it a pointer to the data it needs to hook into your program.
This way the attached object does not need to resolve the names of any global
variables in your program.  This way, you program can be as portable as can
be, constrained by the requirement of using dynamically loaded object files.



Fri, 25 Aug 2000 03:00:00 GMT  
 Setting the address of a variable

Help me please!!! I have been wondering for so long how would u get a
program to get a random line of text from a file or anywhere  even if its
inside the program but I have no idea about how to do this if you could help
I would be MOST GRATEFUL!!!!!!
Derilect :P~



Thu, 31 Aug 2000 03:00:00 GMT  
 Setting the address of a variable

Quote:

>I have two libraries, in one a structure is defined as

>(library 1)
>mystruct_t    myinstance;

>and I pass the address of that structure to another shared library
>(from library1 to library2)
>mystruct_t *exported_instance;

>and want to set
>(library2)
>mystruct_t    imported_instance;

>such that imported_instance and myinstance both use the same address (and
>are both updated as one var).

>1. is this possible?
>2. what is the dereference syntax if it is possible?

You can't define a variable and also say where it is to be.  You
can, however, directly access a variable from another module.

/* library1.c */
mystruct_t myinstance;

/* library1.h */
extern mystruct_t myinstance;

/* library2.c */
#include "library1.h"
...
  myinstance.myfield = 42;
...

However, the variable has to exist (be defined) in one and only
one place.  Here it is in library1, and as a result library2
could not be used without the presence of library1.

                                  Marc Leonard



Fri, 01 Sep 2000 03:00:00 GMT  
 Setting the address of a variable



Quote:
>Help me please!!! I have been wondering for so long how would u get a
>program to get a random line of text from a file or anywhere  even if its
>inside the program but I have no idea about how to do this if you could help
>I would be MOST GRATEFUL!!!!!!
>Derilect :P~

First, I would suggest that you get a good night's sleep, and then
re-frame your question in terms we can understand! Accuracy in
spelling and punctuation is also helpful. If you have a problem with
the C language, post a small but complete program which demonstrates
the problem, explain what you expect the code to do, and explain what
the code actually does. There are a lot of C experts here, but I don't
think there are many psychics among them.

One way to get a random line of text from a file would be to:
1. Open the file
2. Read the file and count the number of lines
3. Rewind the file
4. Generate a random number with a range of 0 to num_lines
5. Seek into the file to the line corresponding to the previously
    generated random number
6. Read in that line
7. Close the file

As to finding a random line of text "anywhere", I haven't a clue. You
might grab a book, open it, and point your finger somewhere on the
page you randomly selected. If you perchance grabbed a C book, you
might want to read it from the beginning, and absorb *all* the lines.

--

Cameron Foster

http://www2.netcom.com/~cdfoster/



Fri, 01 Sep 2000 03:00:00 GMT  
 Setting the address of a variable

|Help me please!!! I have been wondering for so long how would u get a
|program to get a random line of text from a file or anywhere  even if its

Creating a random line of text is trivial if you have no need for it to be
coherent.  If you require that it be part of a natural language, then a
lot of graduate work in linguistics is useful.  If it can be restricted to
text which is part of an artificial language (like C), then just submit
the random text for verification to a grammar-processing program
(see yacc, lex, etc.).  Good luck.

|inside the program but I have no idea about how to do this if you could
help
|I would be MOST GRATEFUL!!!!!!
|Derilect :P~
|
|



Fri, 01 Sep 2000 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Help - I need to set variable A = value held in variable named in variable B

2. How can I set string variable to CString variable

3. How to set an ENV variable like SET for the parent process

4. Handing variable addresses to functions

5. Address of Local Variable

6. Memory Address Reserved once variable is declared??

7. Help with addressing variables directly please

8. Returning address of local variable

9. Getting Address Of Variable Based On String

10. printing address of a variable

11. Returning address of local variable from function.

12. how to get rid of function returns address of local variable

 

 
Powered by phpBB® Forum Software