You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include <stdio.h>
int
main(argc, argv)
char **argv; // argc is implicitly type int
{
printf("Hello world!\n");
return 0;
}
$ corrode test_fail.c
<command-line>:0:1: warning: undefining "__LINE__"
("test_fail.c": line 4): illegal undeclared argument "argc"; check whether a real C compiler accepts this:
main(argc, argv)
$ gcc -c test_fail.c
test_fail.c: In function ‘main’:
test_fail.c:4:1: warning: type of ‘argc’ defaults to ‘int’ [-Wimplicit-int]
main(argc, argv)
^~~~
While this example may seem simple, are a lot of register foo declarations scattered throughout the code, as well as some number of function extern definitions that are weird (that I may open a separate issue for if I can better characterize it).
Maybe this is easy to fix?
The text was updated successfully, but these errors were encountered:
My code infers the int type (and only int, as far as I can tell) in two instances: K&R type signature omission (as above), and variable declarations if another declaration keyword is used.
An example of the latter comes from the original K&R book, emphasis mine:
Section 4.7 Register Variables
The fourth and final storage class is called register. A register declaration advises the compiler that the variable in question will be heavily used. When possible, register variables are placed in machine registers, which may result in smaller and faster programs.
The register declaration looks like:
register int x; register char c;
and so on; the int part may be omitted.
In other words, because register x; is unambiguously a variable declaration, its type can be inferred as int. I think I saw an instance of static x; in there too.
I guess this is what I get for trying to modernise C code that turned 25 this year. 😄
$ cat test_pass.c
$ corrode test_pass.c
$ cat test_fail.c
$ corrode test_fail.c
$ gcc -c test_fail.c
While this example may seem simple, are a lot of
register foo
declarations scattered throughout the code, as well as some number of function extern definitions that are weird (that I may open a separate issue for if I can better characterize it).Maybe this is easy to fix?
The text was updated successfully, but these errors were encountered: