How to augment C with new datatypes painlessly? (Lewis Stiller)
Tue, 07 Aug 90 15:29:04 GMT

          From comp.compilers

Related articles
How to augment C with new datatypes painlessly? (1990-08-07)
| List of all articles for this month |

Newsgroups: comp.lang.c,comp.compilers
From: (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

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*/
if (_special_hardware_equal_longs (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.

[This sounds to me exactly like operator overloading in C++. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.