[aspectc-user] Some questions

Daniel Lohmann daniel.lohmann at informatik.uni-erlangen.de
Wed Sep 14 15:50:58 CEST 2005

Francisco Afonso wrote:

> Hi,
> I have some questions:
> I had a problem of double definition of classes in .ah files when 
> compiling. It was solved by including guards (#ifndef …) in .ah files. 
> I noticed that in the examples no guards are used. Should them be used 
> or inserted by ac++ ?

As with any other header file, aspect files have to be surrounded 
manually by include guards. You are right, even if they are required, 
many of our examples do not show these include guards. The main reasons 
for this (questionable) practice are space limitations for papers and 

> Does AspectC++ work with templates? I have a class with templates and 
> declared a method as a join point. No error was issued during weaving 
> but the code wasn’t affected.

Template support is a major topic on our road map, and still not fully 
implemented. We are optimistic that it is possible to give at least call 
advice to functions in template classes soon. Weaving in template code 
itself (e.g. execution advice or introductions into templates) will take 
some more time.

> My project has some C code in files .c. Can I use AOP with them? I 
> noticed that they are not copied to the destination directory.

AspectC++ can weave in C-Code, the generated output however is always 
C++. For this reason, it does not weave into .c files. You may try to 
compile the parts of your projects with the C++ compiler, too. Depending 
on the quality of the C code this may, however, lead to minor 
incompatibilites and require manual intervention. Afterwards a simple 
rename of the .c files to .cc / .cpp would do the trick.

> Can I use global variables inside the advice code?


> In the around advice without using proceed() how can I return a value?

Either by using the result() pointcut function or the joinpoint API. The 
following example shows the latter:

advice execution ( "int foo()") : around() {
*tjp->result() = 4711;


More information about the aspectc-user mailing list