anti-address operator 
Author Message
 anti-address operator

We all know (or should know) that pointers are variables which contain
address data types. So if we have

  {
  int i=0;
  int *j=&i;
  }

the expression "i" equals "0", the expressions "&i" and "j" both equal the
address of "i", and "*j" also equals "0".

Now, how can we find out which variable whose address is contained in a
pointer. Certainly we can test the expression (&i==j), but one would have
to set up a test for every variable that might be a candidate. C would need
to have a way to find out the identifier based on the address, instead of
the address based on the identifier (an "anti-address" operator or
function, if you will). Depending on how the compiler or the platform sets
up variables for a program, perhaps there is a variable table where the
addresses of all the currently declared variables are stored, and a
function can paruse that table and find which variable is being pointed to
be a given pointer.

Maybe this is simply overcomplicating things and there really cannot be a
conceivable situation in which anything more than (&i==j) is needed, if the
programmer is good enough. Still, while I think typedef is rather useless,
I'm sure someone somewhere has put it to good use ...

--
Matthew Shelton, a.k.a. Xeno,
a.k.a. Marcus Daggersmith

Homepage: www.people.memphis.edu/~mlsheltn



Tue, 24 Oct 2000 03:00:00 GMT  
 anti-address operator

Me too!
Sometimes I also desperately  need the <- operator
to find the pointer that led to the member of a struct.

and the ][ operator to find the index that led to a certain value
in an array.

And I'd like to have the name of the variable that contains the value 42.

--
Happy hacking,

Adriaan van Kessel.
Ingres DBA, C/Unix hacker

(remove NotThere. from the above address)
*** Nederlandstalige zachtwaar is een pijn in de aars ***



Tue, 24 Oct 2000 03:00:00 GMT  
 anti-address operator

[snip]

Quote:

> Now, how can we find out which variable whose address is contained in a
> pointer.

Why would this be needed?

Quote:
> Certainly we can test the expression (&i==j), but one would have
> to set up a test for every variable that might be a candidate.

[snip]

Let us consider a symbolic de{*filter*}.  A pointer contains an address and
the user wants to know the variable that the pointer is pointing to.

Side note:  In an executable program, there are no variable names or
concepts of a variable.  An executable deals with memory locations and
processor registers.  Therefore I am assuming that this topic has a very
limited real-world usage domain.

The method for converting pointer address to symbol name is to search
the symbol table by address, noting also the scope of a variable.  Once
the symbol is found, then all the attributes of the symbol are known.
In a similar manner, one could create this effect by developing a table
of <variable address, symbol name> in the local scope, then searching
the table to resolve a the pointer value.  The table has to be local to
the scope of the variable, since some variables can "disappear" when
executions leaves the scope, such as variables declared inside a
function.

This implies that a symbol table exists.  The symbol table for a given
program must be created.  When a program is compilied with "debug
information", the executable file contains this information.  The format
is compiler & platform dependent.  Post to a platform specific newsgroup
for more information.

For further information, search the web for "compiler theory", and the

--
Thomas Matthews



Tue, 24 Oct 2000 03:00:00 GMT  
 anti-address operator

Quote:

>Now, how can we find out which variable whose address is contained in a
>pointer. Certainly we can test the expression (&i==j), but one would have
>to set up a test for every variable that might be a candidate. C would need
>to have a way to find out the identifier based on the address, instead of
>the address based on the identifier (an "anti-address" operator or
>function, if you will). Depending on how the compiler or the platform sets
>up variables for a program, perhaps there is a variable table where the
>addresses of all the currently declared variables are stored, and a
>function can paruse that table and find which variable is being pointed to
>be a given pointer.

Sorry, that is a silly idea because what would you get out of that
``anti address'' function? Answer: a pointer to that variable,
identical to the pointer that was used as the search key.

Or what if the function was able to give you the name of the variable?
What could you do with that?

One sometimes encounters situations in which it was useful to
use a pointer as a search key to look for an object, but the
aim is not to scan all of the objects in the program's environment.

One example is that of deletion from a linked list. To delete a
node, I need to know what its predecessor is, but since the list
is singly linked, you can't use a ->prev pointer to get
to that node directly. So what you do is search
the linked list, looking for a node whose ->next field
is identical to the pointer to the node being deleted.



Tue, 24 Oct 2000 03:00:00 GMT  
 anti-address operator

On Fri, 08 May 1998 09:50:04 -0600, "Thomas O. Matthews"

Quote:


>[snip]

>> Now, how can we find out which variable whose address is contained in a
>> pointer.

>Why would this be needed?

>> Certainly we can test the expression (&i==j), but one would have
>> to set up a test for every variable that might be a candidate.

>[snip]

>Let us consider a symbolic de{*filter*}.  A pointer contains an address and
>the user wants to know the variable that the pointer is pointing to.

Also, a compiler which performs object bounds checking might use
a pointer as a key to search an internal database of objects to
determine which object is is pointing to. Bounds checking GCC
does this.

The question is, of what practical use, other than debugging,
would such an operation be?



Tue, 24 Oct 2000 03:00:00 GMT  
 anti-address operator

It is agreed that an anti-address operator would probably have no use
outside of debugging, but there have been several situations where I was
using pointers and the results were different from predicted, and it would
be have saved a lot of time to have a hypothetical anti-address operator.
As it was, I was parsing a string to divide it into three separate strings
and the pointer was not starting at the right element for the second and
third strings.

Such an operator, which would return a pointer to a string containing the
identifier of the variable, would have told me immediately that it was
pointing to the wrong element, narrowing the scope of the bug considerably.

--
Matthew Shelton, a.k.a. Xeno,
a.k.a. Marcus Daggersmith

Homepage: www.people.memphis.edu/~mlsheltn



Tue, 24 Oct 2000 03:00:00 GMT  
 anti-address operator



Quote:
>It is agreed that an anti-address operator would probably have no use
>outside of debugging, but there have been several situations where I was
>using pointers and the results were different from predicted, and it would
>be have saved a lot of time to have a hypothetical anti-address operator.
>As it was, I was parsing a string to divide it into three separate strings
>and the pointer was not starting at the right element for the second and
>third strings.

>Such an operator, which would return a pointer to a string containing the
>identifier of the variable, would have told me immediately that it was
>pointing to the wrong element, narrowing the scope of the bug considerably.

What you are asking for is a debugging feature rather than a language
feature. The place to look for something like this would be a symbolic
de{*filter*}.

--
-----------------------------------------


-----------------------------------------



Wed, 25 Oct 2000 03:00:00 GMT  
 anti-address operator

Quote:

> And I'd like to have the name of the variable that contains the value 42.

At least for the variable containig 42 the answer is clear...
the variables name is "_TheMeaningOfLife"...
(at least for al those who know Douglas Adams). >:-)

Regards Rainer



Fri, 27 Oct 2000 03:00:00 GMT  
 anti-address operator

 > Me too!
 > Sometimes I also desperately  need the <- operator
 > to find the pointer that led to the member of a struct.
 >
 > and the ][ operator to find the index that led to a certain value
 > in an array.
 >
 > And I'd like to have the name of the variable that contains the value
42.

Do you know the algorithm that leads to 42?



Fri, 27 Oct 2000 03:00:00 GMT  
 anti-address operator

 >  > And I'd like to have the name of the variable that contains the value
 > 42.
 >
 > Do you know the algorithm that leads to 42?

Yup.  6 * 9.
--
dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn  amsterdam, nederland; http://www.cwi.nl/~dik/



Fri, 27 Oct 2000 03:00:00 GMT  
 anti-address operator

Quote:


> > And I'd like to have the name of the variable that contains the value 42.

> At least for the variable containig 42 the answer is clear...
> the variables name is "_TheMeaningOfLife"...
> (at least for al those who know Douglas Adams). >:-)

Uhm, not really, more like
   theAnswerToTheQuestionOfLifeTheUniverseAndEverything

acceptable short form:
   lifeTheUniverseAndEverything

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Fri, 27 Oct 2000 03:00:00 GMT  
 anti-address operator

Quote:


>  > Me too!
>  > Sometimes I also desperately  need the <- operator
>  > to find the pointer that led to the member of a struct.

>  > and the ][ operator to find the index that led to a certain value
>  > in an array.

>  > And I'd like to have the name of the variable that contains the value
> 42.

> Do you know the algorithm that leads to 42?

6 * 7


Fri, 27 Oct 2000 03:00:00 GMT  
 anti-address operator

Sorry for not quoting the whole thread...

This is the funniest thread I can ever remember in this newsgroup.

I appreciate the restraint of those attempting to add grumpiness to
this newsgroup.

thanks,

-- glen



Fri, 27 Oct 2000 03:00:00 GMT  
 anti-address operator

Quote:



>  >  > And I'd like to have the name of the variable that contains the value
>  > 42.

>  > Do you know the algorithm that leads to 42?

> Yup.  6 * 9.

Iff 9 = 7.

--

I believe we can change anything.
I believe in my dream.
    - Joe Satriani



Fri, 27 Oct 2000 03:00:00 GMT  
 anti-address operator

Quote:

> Uhm, not really, more like
>    theAnswerToTheQuestionOfLifeTheUniverseAndEverything

> acceptable short form:
>    lifeTheUniverseAndEverything

Acceptable short form for those not {*filter*}ed to certain ugly and needlessly
verbose naming styles:
        answer

--
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

Attempting to write in a hybrid which can be compiled by either a C compiler
or a C++ compiler produces a compromise language which combines the drawbacks
of both with the advantages of neither.



Fri, 27 Oct 2000 03:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. coding anti-anti-standards [was: coding anti-standards]

2. C Question - pointer & address-operator

3. memcpy ( with address operator or not? )

4. Why use address-of operator (&)??

5. The & (address) operator and register allocation

6. Address of vector::operator[n]() if instantiated with C-array type

7. anti-Spyware source

8. Ansi C memcpy outperforms ASM using anti-pipeline stalling

9. Anti Virus source code

10. BEA and webservices [anti - java.advocacy]

11. Quick Sort, quicker, stable and anti-degeneration

12. The Anti-Ice Cream Truck Homepage

 

 
Powered by phpBB® Forum Software