[aspectc-user] adding variables and using them

Fabian Scheler fabian.scheler at gmail.com
Fri Jul 15 13:35:35 CEST 2005


> Thanks Fabian for your reply :) I just wanted to expand my question so
> that it would address my biggest problem. first how would you assign the
> tjp->target()->x if x itself was a pointer?

well, I would dereference the pointer, just like

*(tjp->target()->x) = someNumber;

of course you have to allocate memory for x before you try to
dereference x. The target()-method returns a pointer to an object that
is the target of a call. An example:

class myClass {
  void myMethod();
  void yourMethod();

int main() {
  myClass myClassObject;


aspect SomeAspect {
  advice call("% myClass::%(...)") : after() {
    myClass* ptrToMyClassObj = tjp-target();
    /* do something with ptrToMyClassObj */

in this example target() returns a pointer to the object
'myClassObject', you can do with this pointer what you can do with any
pointer to an object, e.g. call a method of the object:


> and second, would the following make any sense? I'm trying to add the
> variable that I just created for the class to the constructor. I know it
> wouldnt allow me to touch the constructor using regular advices so I'm
> wondering if this would work( although the compiler is complaining and
> gicing segmentaion faults)
> aspect asp :public A {
> public:
> asp(int ix):A(ix){} //assume A(int x) is constructor
> pointcut calls()=  "A" ;
> advice calls() : void initialize () {p=0;j=0;}
> advice calls(): int abc;
> advice construction (calls()) :before(){ abc=0;}
> static asp* aspectof() {
>   static asp asp_instance(5);
>   return &asp_instance;
> }};

I think that should work, but again you have to use 'tjp->that()->abc
= 0' instead of 'abc = 0'. In fact this quite common: insert a
variable via an introduction and initialize it via

> Thanks again Fabian,
> Promise not to bother you as often :)

No problem, I hope I was able to help you, but please always reply to
the mailing list, too, so all readers of the mailing list can partake
in a particular thread.

Ciao, Fabian.

More information about the aspectc-user mailing list