Self-compiling C code - cc500

This is a discussion on Self-compiling C code - cc500 within the C Programming forums, part of the General Programming Boards category; Hi there, I am making a very simple piece of software in C for my final major project for a ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    Self-compiling C code - cc500

    Hi there,

    I am making a very simple piece of software in C for my final major project for a cultural studies MA. I am exploring software culture and software development methodologies.

    The software itself needs to be very simple and to be able to self compile. Because I have little knowledge of C to date, I have choosen the smallest and simplest (non-obfuscated) C compiler I could find.

    Details of cc500 plus source code are available here:
    CC500: a tiny self-hosting C compiler

    There are very simple instructions in order to compile and self-compile the code. They are as follows:

    Compilation:

    Code:
    gcc cc500.c -o cc500_1
    Self-compilation:
    Code:
    ./cc500_1 < cc500.c > cc500_2
    chmod +x cc500_2

    This process works fine but the next step I need to perform is to use cc500_2 to then compile a very simple application that I have created.

    I have looked into the cc500.c code and it seems that the only supported functions are:

    Code:
    void exit(int);
    int getchar(void);
    void *malloc(int);
    int putchar(int);
    Therefore I have tried to compile the following application using cc500_2:

    Code:
    #include <stdio.h>
    
    main(){
           int c;
           while((c = getchar() != EOF)
                   putchar(c);
    }
    I have not been successful with this. A zero KB files is generated. I tried using the gcc to compile the same application and it works ok so I assume the logic is acceptable.
    I have also tried removing the #include <stdio.h> line because I'm not sure if this is relevant with the tc500 compiler.

    Thanks in advance for any advice.

    Gareth

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    999
    instead of "main()", try "int main(void)", and add "return 0;" after putchar

  3. #3
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    999
    Also, "while((c = getchar() != EOF)" (extra parenthesis)

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    Read the page:

    "There is no preprocessor."

    So remove the #include statement.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,671
    EOF is also a macro from <stdio.h>, so you can't use it.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  6. #6
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    999
    You'd be better off to use a more powerful and more well known "small" compiler: TCC : Tiny C Compiler

  7. #7
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    I think I used every all of the advice given in this thread and have managed to get a very simple script to compile. However, when executed it is not performing as I was expecting. I think I am very restricted in what I can do using this extra small compiler. I will look into TCC.

    Many thanks,
    Gareth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Source code not compiling...
    By darren78 in forum C++ Programming
    Replies: 6
    Last Post: 11-23-2009, 07:53 AM
  2. Replies: 1
    Last Post: 03-01-2006, 03:07 AM
  3. compiling c code
    By MadCow257 in forum C++ Programming
    Replies: 2
    Last Post: 02-16-2006, 09:26 AM
  4. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21