[aspectc-user] Forwarded: set and get methods

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Mon May 9 11:00:48 CEST 2005


Hi Donal,

the aspectc-user mailing list rejected your posting, because you are not 
subscribed. This is an important restriction to avoid spam on the list. 
Please subscribe before you post your next mail.

Here is your message:
---
Hi there,

I'm trying to evaluate aspectc++ for an internal project.

Looking over the discussion archives, I noticed that set/get 
functionality is missing due to the 'aliasing' problem.  Can someone 
point me to a description of this problem?  Does it apply to 
well-defined data, and here I mean members of a struct/class.

Donal
---

Here is an example that illustrates the problem for members of classes:
---
#include <iostream>
using namespace std;

int *alias = 0;

class X {
   int attr;
public:
   void func() {
     alias = &attr;
   }
   void print() {
     cout << attr << endl;
   }
};

int main () {
   X x;
   x.func ();
   cout << &x << " " << alias << endl;
   *alias = 1234;
   x.print ();
}
---
output:
spinczyk at faui48:~> g++ -Wall -o t t.cc
spinczyk at faui48:~> ./t
0xbfffef14 0xbfffef14
1234
---

This program, which is correct C++ code, uses no problematic type-casts 
and compiles without warnings even with 'g++ -Wall'. It creates an alias 
for an attribute of the object 'x'. The expression statement '*alias = 
1234;' sets the value of the attribute 'X::attr'.

It wouldn't be very complicated to detect this 'set' operation by 
weaving code that compares the value of 'alias' with the addresses of 
all monitored objects, but it would be very expensive. Static analysis 
might help some cases, but at least if the value of an alias depends on 
input runtime support is needed. You will find an overview about the 
static analysis work on 'pointer aliasing' in [1]. A lot of this 
theoretical work has been done in languages that are a subset of C.

-Olaf

[1] X.-X. S. Zhang. Practical Pointer Aliasing Analysis for C. PhD 
Thesis, Rutgers University, 1998.



More information about the aspectc-user mailing list