cs50 / help50-deprecated

This is help50, a command-line tool that helps students understand error messages.
https://cs50.harvard.edu/
GNU General Public License v3.0
62 stars 64 forks source link

Recognize when a function has already been prototyped. #283

Open pdhixenbaugh opened 4 years ago

pdhixenbaugh commented 4 years ago

When compiling C code, and make outputs error: a parameter list without types is only allowed in a function definition, it may be the following case:

https://stackoverflow.com/questions/49571922/error-a-parameter-list-without-types-is-only-allowed-in-a-function-definition

help50 could say something like, clang thinks you are declaring your function here. Are you trying to call it instead?

(This is in reference to the Short on Debugging, which suggests submitting new use cases to the help50 github repo.)

Hope this helps!

P.S. I am working on pset3; can't wait to get to the python lectures, where I can start thinking about submitting pull requests.

cmlsharp commented 4 years ago

This is a good suggestion. Unfortunately, from the error alone, we can't tell if there was actually a prototype earlier in the file. That is, we can't tell the difference between someone actually writing a bad prototype e.g.:

bool tri(x, y, z);

int main(void)
{
}

and someone incorrectly calling the function (which is what you did) e.g.

bool tri(int x, int y, int z);

int main(void)
{
    int x = 1, y = 2, z = 3;
    bool tri(x, y, z);
}

since both yield the same error message. Because of that, whatever our "better" error message is, it has to be generic enough to cover both cases. This means we can't state that a prototype for the function occured earlier since we don't know that to be the case.

Also, just fyi, this is really better suited for the cs50/helpers repo. This repo contains the tool that downloads the helpers and runs them, but the helpers repo contains the actual translation logic.

Maybe something like, It looks like you are trying to write a function prototype on line <LINE> but you have not specified the types of the arguments. I don't know if this will be all that helpful in your use case though since you weren't in fact trying to prototype a function. You were trying to call it.

pdhixenbaugh commented 3 years ago

Also, just fyi, this is really better suited for the cs50/helpers repo. This repo contains the tool that downloads the helpers and runs them, but the helpers repo contains the actual translation logic.

Thanks for the tip!

Maybe something like, It looks like you are trying to write a function prototype on line but you have not specified the types of the arguments. I don't know if this will be all that helpful in your use case though since you weren't in fact trying to prototype a function. You were trying to call it.

I think that would still be useful. Help50 was most helpful to me when it provided me with a second explanation of an error message. Given the explanation and the actual error message, I could usually figure out what was going on. So from that error message, I would see that it had to do with function prototyping, which is not immediately evident in make's output.

Thanks for your response!