[aspectc-user] adding variables and using them

Fabian Scheler fabian.scheler at gmail.com
Tue Jul 19 09:41:59 CEST 2005


Hi Jamal,

> It still gives out a segmentation fault. It compiles fine though and is
> syntactically correct but doesn't run. Could this be a possible bug? ( I
> use "ag++ -o t A.cxx" to compile and then "./t" to run it and thats when I
> get the segmentation fault messege).

ok, now I can explain the segfault. Why the programm was running
properly yesterday I just don't know, but I am able to reproduce the
segfault now. This is what happens:

-> you create an instance of class A
    -> constructions advice is executed
        -> instance of the aspect is fetched via the aspectof()-method
            -> instance of Asp is created (and with that an instance
of A, as Asp
                inherits from A)
                -> constructions advice is executed
                    -> instance of the aspect is fetched via the
aspectof()-method
                        -> instance of Asp is created (and with that
an instance of A, as Asp
                            inherits from A)
                            -> ...

as you see, this will end up in an endless recursion consuming all the
memory available for the stack => segfault

This is not a problem of AspectC++ but of the C++-Compiler or C++,
this problem depends on the point in time, when the static variable in
the aspectof() really is created, I don't know what the C++ says about
that.

For future use: better avoid constructions like that (inheriting from
a class that is affected by construction advice of the aspect
inheriting from it), the variable abc also can become a member of the
aspect itself and thus can also be initialized within the aspects
constructor, or: do not inherit from A within the aspect.

I hope that helps.

Ciao, Fabian




More information about the aspectc-user mailing list