Related articles |
---|
How to augment C with new datatypes painlessly? stiller@cmx.npac.syr.edu (1990-08-07) |
Newsgroups: | comp.lang.c,comp.compilers |
From: | stiller@cmx.npac.syr.edu (Lewis Stiller) |
Keywords: | C, question, OOP, design |
Organization: | Northeast Parallel Architectures Center, Syracuse NY |
Date: | Tue, 07 Aug 90 15:29:04 GMT |
I would like to augment C to handle certain machine dependent types.
Ideally, a preprocessor should look at the source code, and emit the same
source, except that whenever certain arithmetic operations and declarations
are performed on a variable in one of these new types, the appropriate
standard C function calls are emitted. The only trickiness comes in handling
complicated type declarations, and I don't want to recode the wheel here.
I don't need a whole C compiler, just an interface to C that will cleanly
handle the new types: GNU C or whatever can handle the new functions. But
for debugging and optimization (by hand) the preprocessor must output stuff
similar to the C source.
For example, suppose I have special hardware to handle superlong ints, of
say > 1024 bits. I would want to code in standard C, except declare some
variables to be of type
superlong x,y,z; /* x,y,z are superlong ints in the special
hardware*/
or even have some syntax for variable-width superlong ints. Then, when the
compiler sees code like:
printf("unchanged\n"); /* stuff unchanged*/
superlong x,y,z;
if (x==y) z=x+y;
it should output code like:
printf("unchanged\n"); /* stuff unchanged*/
_special_hardware_allocate(x,LONG);
_special_hardware_allocate(y,LONG);
_special_hardware_allocate(z,LONG);
if (_special_hardware_equal_longs (x,y))
_special_hardware_plus_longs_3(z,x,y);
....
It must handle superlongs that are members of complicated struct/typedef
constructions correctly.
Anyway, I imagine this problem comes up a lot, and wonder if there are any
Unix sources for handling it. A well-written and easy to modify parser for C
should do the trick.
lewis
[This sounds to me exactly like operator overloading in C++. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.