Related articles |
---|
Basic "C++ like" Object macros in C jswitte@bloomington.in.us (Jim Witte) (2004-02-26) |
From: | Jim Witte <jswitte@bloomington.in.us> |
Newsgroups: | comp.compilers |
Date: | 26 Feb 2004 01:06:01 -0500 |
Organization: | IU |
Keywords: | C++, C, OOP, question |
Posted-Date: | 26 Feb 2004 01:06:01 EST |
Does anyone know of a simple macro library somewhere for implementing
the syntactic sugar of basic C++ OO syntax in plain C? By simple, I mean:
1. class-method construction macros, so that
float myClass::aMethod(int a, ...) would epand to
float myClass_aMethod(struct myClass* thisPtr, int a, ...)
2. reproduction of the 'this' syntax - I can do this already
3. method-call syntax:
anObject:aMethod(5) expands to
myClass_aMethod(anObject, 5) where anObject is a pointer to an object
4. constructor syntax:
myClass:myClass(int a=5) expands to
void myClass_init(int a)
I've found library (Kazlib) which implements some kind of
exception-processing mechanism in plain C, and I've made a few macros
to do some of the above, but I don't know much about C-macro writing,
and since you can't write polymorphic macros, I don't know how you'd
get a macro for (1) above to work with an optional return value and
(possibly) multiple parameters (other than the instance object
pointer)
As for the obvious question of why I don't just use C++ - the
professor won't let us (it's a data structures course), and I like a
challenge (although in this case it's probably just not worth the
trouble..)
Jim Witte
jswitte@bloomington.in.us
Indiana University CS
Return to the
comp.compilers page.
Search the
comp.compilers archives again.