views:

383

answers:

4

Has anyone seen or written their own framework for doing Aspect Oriented Programming in C?

Not C++ -- I've seen already that there's AspectC which is really C++.

Involved in embedded software development which requires C only.

I am not asking how to do it, only whether someone has done it already.


EDIT:

Need clarification on one of the responses.

Mads Elvheim

It was not my position that AspectC is C++. Rather, I had searched for AOP for C and only gotten to http://www.aspectc.org/, which certainly sounded from the URL like the place, but it begins,

"With the AspectC++ project we extend the AspectJ approach to C/C++. It is a set of C++ language extensions to facilitate aspect-oriented programming with C/C++"

which made me think that there was no AOP from them just for C. The link you sent looks more promising, in that its web page title is "AOP for C". But here at this link, http://www.cs.ubc.ca/labs/spl/projects/aspectc.html, I can't find any code, so I'm not sure. Do you know where to find code on that site?

As for http://sailhome.cs.queensu.ca/~bram/aspicere/index.html#examples, I've already found the code examples there, so I'll look at them.

A: 

This link contains information about various AOP tools available for different languages.

You can also take a look at Xweaver

atv
Thanks but no C there.
talkaboutquality
oh but xweaver web site talks about providing C support. I think its still under development. I have used aspectJ for AOP.
atv
+1  A: 

Look here(aspicere) and here(aspectc).

Mads Elvheim
He mentioned that in his eyes AspectC is really just C++
MattC
Oh, I didn't notice. Apologies.
Mads Elvheim
Actually could be OK -- see my edit in the question.
talkaboutquality
+1  A: 

Yes, someone has done it: answer at end. I will start of by some discussion.

C is a language that achieves elegance by the application of techniques. Other languages are rich with constructs that make it easier to program various paradigms. You can pretty much achieve any paradigm in C by applying technique.

The book you need to read is Generative Programming. You can find really advanced generative programming tools and document ion which makes use of aspects from imatix . Download their source packages and read any documentation you can find. The techniques from imatix have to be studied -- they call all of what they do model oriented programming -- however, it is related.

To sort of make the connection between model oriented programming and AOP, the placement of point-cuts are a procedural high level model of the problem you are trying to solve. Please read the generative programming book to see how everything fits.

The openAMQ reference implementation uses the generative tools built by imatix.

Hassan Syed
I have not read that book yet. I did go to a lecture once on that subject. From the reviews of the book, everyone talks only about C++, not C. Is C++ required (or OO-emulation of C++ in C) in order to do what imatix does?
talkaboutquality
imatix target C specifically with their technologies. however, do not be distracted with the fact that they are using C++ as a target, you can express any paradigm from C++ in C.
Hassan Syed
This isn't anything like AspectC. It doesn't parse C code. It doesn't obviously have pointcuts. It doesn't have "advice"; rather it is a template based code generator. And yes, I've read the Generative Programming book.
Ira Baxter
What do you mean by "this" ? pointcuts aren't fairy dust that need special appreciation, the paradigm can easily be implemented on top of code generators.
Hassan Syed
+1  A: 

Aspect-oriented programming is just a special case of program transformation.

A special kind of program transformation is a source-to-source transformation, written as:

lhs_pattern ==> rhs_pattern if condition

where the patterns are written as parameterized text in the language being transformed. For example,

 \x=\x+1 ==>  \x++ if x!=0

If you can transform your program arbitrarily using a tool, you can do AOP easily. To insert code around a function call to foo, you can write:

 foo(\args); ==>  {  code1fragment; foo(\args); code2fragment }

Thus we have coded a pointcut and advice directly as a program transformation.

Our DMS Software Reengineering Toolkit is a engine that can apply program transformations to many real languages, including C and C++.

We have used DMS to carry out many kinds of transformations on C code. Our test coverage and profiler tools operate by basically applying what are equivalent to aspects for collecting instrumentation data.

To learn more, see Aspect Oriented Programming with DMS

Ira Baxter