[Coco] ANSI -> K&R Code Conversion

James Dessart james at skwirl.ca
Wed Mar 16 22:35:06 EST 2005


On 16-Mar-05, at 9:19 PM, Mannequin* wrote:

> First, what kind of interest is there in this kind of project?

I think updating the current one is where the effort would best be 
spent.

> Will this aid us until there can be an ANSI C compatible compiler 
> written for
> the Coco?

The thing is, if you can parse C to the point of being able to convert 
it from K&R to ANSI, or vice verse, you're already part of the way to 
having an actual C compiler. Work on the one we've got, get it going, 
it'll be ready sooner and thus useable.

Of course, if you want to write a C-like language parser using flex and 
bison, it should be relatively easy, and then you simply make it 
generate nothing but 6809 code, and it might be just as easy as writing 
a backend to sdcc. I, for one, am not comfortable embarking on such an 
adventure. :)

> Last, but certainly not least, what are the major dividing points 
> between the
> two styles? I'm the proud owner of both K&R 1 & 2, so I can look 
> through the
> books, but I want everyone's opinion here, so I don't miss something 
> rather
> important. :)

The main thing is function declarations. int is the default return 
type, and if you don't specify a return type, you get int. Many K&R 
functions simply don't declare a return type. The parameter list is the 
next difference, between the parentheses you have only the parameter 
names, separated by commas. Then on the following lines you have them 
listed out, with type, as if they were local variables, but outside of 
the function body braces.

I don't believe you can pass anything but basic types, and even then, 
you can only pass them as pointer-sized types (so char*[] or the like).

I believe that prototypes are optional, because at the time they simply 
built a two-pass compiler. I think that requiring prototypes came into 
fashion to facilitate writing one-pass compilers, but this is just 
conjecture.

There are probably other differences to do with structs and the like, 
but I'm not aware of the specifics. There's a lot of K&R source in the 
OS-9 PROG directory on RTSI, it might help/

James




More information about the Coco mailing list