AspectC++ is an aspect-oriented extension of C and C++ languages. It has a source-to-source compiler, which translates AspectC++ source code into compilable C++. The compiler is available under the GNU GPL, though some extensions specific to Microsoft Windows are only available through pure-systems GmbH.
Aspect-oriented programming allows modularizing cross-cutting concerns in a single module, an aspect. Aspects can modify existing classes, but most commonly they provide 'advice' that runs before, after, or around existing functionality.
Example
All calls to a specific function can be traced using an aspect, rather than inserting 'cerr' or print statements in many places:
aspect Tracer { advice call("% %Iter::Reset(...)") : before() { cerr << "about to call Iter::Reset for " << JoinPoint::signature() << endl; } };The Tracer aspect will print out a message before any call to %Iter::Reset. The %Iter syntax means that it will match all classes that end in Iter.
Each 'matched' location in the source code is called a join point—the advice is joined to (or advises) that code. AspectC++ provides a join point API to provide and access to information about the join point. For example, the function:
JoinPoint::signature()returns the name of the function (that matched %Iter::Reset) that is about to be called.
The join point API also provides compile-time type information that can be used within an aspect to access the type or the value of the arguments and the return type and return value of a method or function.
- Spinczyk, Olaf; Gal, Andreas; Schröder-Preikschat, Wolfgang (1 February 2002). "AspectC++: an aspect-oriented extension to the C++ programming language". Proceedings of the Fortieth International Conference on Tools Pacific: Objects for Internet, Mobile and Embedded Applications. Australian Computer Society: 53–60.
- Spinczyk, Olaf; Lohmann, Daniel (1 October 2007). "The design and implementation of AspectC++". Knowledge-Based Systems. 20 (7): 636–651. doi:10.1016/j.knosys.2007.05.004. ISSN 0950-7051. Retrieved 31 March 2025.
- Mahrenholz, D.; Spinczyk, O.; Schroder-Preikschat, W. (April 2002). "Program instrumentation for debugging and monitoring with AspectC++". Proceedings Fifth IEEE International Symposium on Object-Oriented Real-Time Distributed Computing. ISIRC 2002. Institute of Electrical and Electronics Engineers. pp. 249–256. doi:10.1109/ISORC.2002.1003713. ISBN 0-7695-1558-4. Retrieved 31 March 2025.
- Lohmann, Daniel; Spinczyk, Olaf (22 October 2006). "Developing embedded software product lines with AspectC++". Companion to the 21st ACM SIGPLAN Symposium on Object-oriented Programming Systems, Languages, and Applications. Association for Computing Machinery: 740–742. doi:10.1145/1176617.1176702. ISBN 1-59593-491-X.