New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Compiling: Warnings and Errors #10

Closed
theideasmith opened this Issue Nov 9, 2014 · 7 comments

Comments

Projects
None yet
5 participants
@theideasmith

theideasmith commented Nov 9, 2014

This project is really cool and i'm aching to give it a try.
But...
I curled the raw code and saved it to my hard drive, and then ran gcc -o c4 c4.c and got a list of 20 errors. Then, after realizing my machine might be 64 bit, I ran gcc again with -m32 included, and still got the following list of compiler errors and warnings.

Any idea how to bypass this?

$ gcc c4.c
c4.c:45:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
next()
^~~~
c4.c:49:21: error: non-void function 'next' should return a value
      [-Wreturn-type]
    if (!(tk = *p)) return;
                    ^
c4.c:54:23: warning: field precision should have type 'int', but argument has
      type 'long' [-Wformat]
        printf("%d: %.*s", line, p - lp, lp);
                    ~~^~         ~~~~~~
c4.c:75:39: warning: cast to 'char *' from smaller integer type 'int'
      [-Wint-to-pointer-cast]
        if (tk == id[Hash] && !memcmp((char *)id[Name], pp, p - pp)) { t...
                                      ^
c4.c:75:85: error: non-void function 'next' should return a value
      [-Wreturn-type]
  ...&& !memcmp((char *)id[Name], pp, p - pp)) { tk = id[Tk]; return; }
                                                              ^
c4.c:81:7: error: non-void function 'next' should return a value [-Wreturn-type]
      return;
      ^
c4.c:87:7: error: non-void function 'next' should return a value [-Wreturn-type]
      return;
      ^
c4.c:95:9: error: non-void function 'next' should return a value [-Wreturn-type]
        return;
        ^
c4.c:108:7: error: non-void function 'next' should return a value
      [-Wreturn-type]
      return;
      ^
c4.c:110:78: error: non-void function 'next' should return a value
      [-Wreturn-type]
  ...== '=') { if (*p == '=') { ++p; tk = Eq; } else tk = Assign; return; }
                                                                  ^
c4.c:111:76: error: non-void function 'next' should return a value
      [-Wreturn-type]
  ...(tk == '+') { if (*p == '+') { ++p; tk = Inc; } else tk = Add; return; }
                                                                    ^
c4.c:112:76: error: non-void function 'next' should return a value
      [-Wreturn-type]
  ...(tk == '-') { if (*p == '-') { ++p; tk = Dec; } else tk = Sub; return; }
                                                                    ^
c4.c:113:60: error: non-void function 'next' should return a value
      [-Wreturn-type]
    else if (tk == '!') { if (*p == '=') { ++p; tk = Ne; } return; }
                                                           ^
c4.c:114:113: error: non-void function 'next' should return a value
      [-Wreturn-type]
  ...= Le; } else if (*p == '<') { ++p; tk = Shl; } else tk = Lt; return; }
                                                                  ^
c4.c:115:113: error: non-void function 'next' should return a value
      [-Wreturn-type]
  ...= Ge; } else if (*p == '>') { ++p; tk = Shr; } else tk = Gt; return; }
                                                                  ^
c4.c:116:75: error: non-void function 'next' should return a value
      [-Wreturn-type]
  ...(tk == '|') { if (*p == '|') { ++p; tk = Lor; } else tk = Or; return; }
                                                                   ^
c4.c:117:76: error: non-void function 'next' should return a value
      [-Wreturn-type]
  ...(tk == '&') { if (*p == '&') { ++p; tk = Lan; } else tk = And; return; }
                                                                    ^
c4.c:118:37: error: non-void function 'next' should return a value
      [-Wreturn-type]
    else if (tk == '^') { tk = Xor; return; }
                                    ^
c4.c:119:37: error: non-void function 'next' should return a value
      [-Wreturn-type]
    else if (tk == '%') { tk = Mod; return; }
                                    ^
c4.c:120:37: error: non-void function 'next' should return a value
      [-Wreturn-type]
    else if (tk == '*') { tk = Mul; return; }
                                    ^
c4.c:121:38: error: non-void function 'next' should return a value
      [-Wreturn-type]
    else if (tk == '[') { tk = Brak; return; }
                                     ^
c4.c:122:38: error: non-void function 'next' should return a value
      [-Wreturn-type]
    else if (tk == '?') { tk = Cond; return; }
                                     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
3 warnings and 20 errors generated. ```
@harrisonstatham

This comment has been minimized.

Show comment
Hide comment
@harrisonstatham

harrisonstatham Nov 9, 2014

All you need to do is add a void before each function declaration.

Edit - I forgot to mention that the main function needs a int added as well.

The final function declarations should look like:

void next();
void expr(int lev);
void stmt();
int main();

harrisonstatham commented Nov 9, 2014

All you need to do is add a void before each function declaration.

Edit - I forgot to mention that the main function needs a int added as well.

The final function declarations should look like:

void next();
void expr(int lev);
void stmt();
int main();

@rswier

This comment has been minimized.

Show comment
Hide comment
@rswier

rswier Nov 9, 2014

Owner

Changing c4.c too much (for instance adding void), breaks the ability of the compiler to compile and run itself (i.e. ./c4 c4.c hello.c)

On my machine (32 bit, gcc) I get no warnings. I believe others have had success with other OS's and C compilers with the right combination of compile-time switches. Take a look through the other problem/issues logs.

I hope that once people get a clean compile, they can send me the exact machine/OS/compiler configuration and command line switches used.

Owner

rswier commented Nov 9, 2014

Changing c4.c too much (for instance adding void), breaks the ability of the compiler to compile and run itself (i.e. ./c4 c4.c hello.c)

On my machine (32 bit, gcc) I get no warnings. I believe others have had success with other OS's and C compilers with the right combination of compile-time switches. Take a look through the other problem/issues logs.

I hope that once people get a clean compile, they can send me the exact machine/OS/compiler configuration and command line switches used.

@rswier

This comment has been minimized.

Show comment
Hide comment
@rswier

rswier Nov 9, 2014

Owner

If you want to try it right now, the code works in the jor1k javascript linux emulator

http://simulationcorner.net/index.php?page=jor1k

From github, press download ZIP.
Upload the file to jor1k.
In jor1k type:
unzip c4-master.zip
cd c4-master
gcc -o c4 c4.c
./c4 hello.c

Hopefully that should work!

Owner

rswier commented Nov 9, 2014

If you want to try it right now, the code works in the jor1k javascript linux emulator

http://simulationcorner.net/index.php?page=jor1k

From github, press download ZIP.
Upload the file to jor1k.
In jor1k type:
unzip c4-master.zip
cd c4-master
gcc -o c4 c4.c
./c4 hello.c

Hopefully that should work!

@aatxe

This comment has been minimized.

Show comment
Hide comment
@aatxe

aatxe Dec 4, 2014

You can compile it with -Wno-return-type and this will fix your compilation issues.

aatxe commented Dec 4, 2014

You can compile it with -Wno-return-type and this will fix your compilation issues.

@feroldi

This comment has been minimized.

Show comment
Hide comment
@feroldi

feroldi Dec 5, 2014

I don't know if putting void to main type return is a good idea. The OS needs to know which situation the program exited, and the Main function NEEDS to return something. If there's no return, the OS comes to "wtf happened here?".

feroldi commented Dec 5, 2014

I don't know if putting void to main type return is a good idea. The OS needs to know which situation the program exited, and the Main function NEEDS to return something. If there's no return, the OS comes to "wtf happened here?".

@aatxe

This comment has been minimized.

Show comment
Hide comment
@aatxe

aatxe Dec 5, 2014

Is it a good idea? Probably not. Is this C and can we basically do whatever want as a result? Yeah. This project doesn't exactly seem like something that's aiming for production use. Just tell the compiler to ignore the return type errors. It'll build.

aatxe commented Dec 5, 2014

Is it a good idea? Probably not. Is this C and can we basically do whatever want as a result? Yeah. This project doesn't exactly seem like something that's aiming for production use. Just tell the compiler to ignore the return type errors. It'll build.

@feroldi

This comment has been minimized.

Show comment
Hide comment
@feroldi

feroldi commented Dec 5, 2014

Oh, ok.

@aatxe aatxe referenced this issue Dec 5, 2014

Closed

Update c4.c #3

@rswier rswier closed this Dec 22, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment