[comp.sys.mac.programmer] LSC prototypes & ANSI

engber@speedy.cs.wisc.edu (Mike Engber) (09/09/88)

There have been a lot of messages lately about LSC's prototypes. Most
people wish for the full implementation of them so the can use them to
declare functions.

However, has anyone noticed that the way things are implemented
currently may make your code incompatible with the actual ANSI
standard?

I think that people who are using the prototypes and care about being
able to easily port their code should take the time to read this.

Below is an edited (ellaborated) version of the second letter I sent
to Rich Segal on this subject. I never got a response to  the 2nd letter
so I don't know if he didn't get it or what.

-ME
-----

You'll recall that I sent you a previous message pointing out that your
prototype implementation's handling of old style declarations doesn't conform
to the ANSI draft.

My example was something like:
int foo(c)
 char c;
{}

Which ANSI says should only match a prototype of:
 int foo(int);
but, LSC wants:
 int foo(char);

This is because foo should expect c to passed as a char. Functions declared
with the old style expect char arguments to be expanded to ints.
My reference for this info is Plum's Book, 'Notes on the Draft C Standard.'

I was thinking about your response (you've only implemented part of the
draft). I think more accurately you should say that you've implemented
an approximation of the draft (with respect to prototypes). The reason
I'm making this point is that if you fix the above problem, then almost
all existing LSC code that uses prototypes is going to break.

Now, I'm glad you did implememnt the prototypes you did because It lets me
program more reliably, but I think the issue I've raised deserves some
immediate attention. I think a lot of people use the prototypes, and when
you get around to fixing up your implementation you will be faced with the
choice of conforming to ANSI exactly or breaking a lot of existing code.

The reason I haven't posted this to the net is that it's a pretty subtle
detail in the draft. (I stumbled on it accidentally) I don't think anyone
is going to care (until it breaks their code) Maybe you guys could think
about how you're going to resolve the problem and post something about it.
That way I can make sure I'm writing code that will be compatible with
future versions.

As far as what I would suggest goes, I don't see any easy (user invisible)
solution to this problem because when you conform to ANSI the existing
code becomes illegal and therefore, must be changed.

The best solution I came up with is:
 1)when LSC detects a prototype error of this sort it should flag it and
   ask the user if he wants to:
    a)fix the prototype
    b)change the function definition to prototype form
 2)then fix it for him (should be simple to do)

Option 1b) might also be a nice thing to have around for people who
decide they want to turn require prototypes on for some old projects.

Anyway, I hope you don't think I'm being critical, I'm just trying to
prevent some problems from occuring.

-ME

brad@cayman.COM (Brad Parker) (09/11/88)

From article <6231@spool.cs.wisc.edu>, by engber@speedy.cs.wisc.edu
(Mike Engber):
> ...
> Now, I'm glad you did implememnt the prototypes you did because It
lets me
> program more reliably, but I think the issue I've raised deserves some
> immediate attention. I think a lot of people use the prototypes, and when
> you get around to fixing up your implementation you will be faced with the
> choice of conforming to ANSI exactly or breaking a lot of existing code.

This is a good point. We write code here which often starts out in as LSC
environment but later ends up in an ANSI compiler. We have been forced to
#ifdef our prototypes depending on the environment. The LSC prototypes are
not correct in the ANSI world. Most distressing.

> 
> The reason I haven't posted this to the net is that it's a pretty subtle
> detail in the draft. (I stumbled on it accidentally) I don't think anyone
> is going to care (until it breaks their code) Maybe you guys could think
> about how you're going to resolve the problem and post something about it.
> That way I can make sure I'm writing code that will be compatible with
> future versions.
> 

We stumbled on this a while ago. I would like to see a compiler switch which
chooses between "LSC prototypes" and "ANSI prototypes". This would make the
migration less painfull.



-- 
"What will you do when you wake up one morning to find that God's made you
blind in a beautiful person's world and all those great recepies have let you
down, and you're twenty and a half and you're not getting age where you go look
for the boys 'says I love you lets get married and have kids." -Billy Bragg.