Xcode Apple Compile

This is a discussion on Xcode Apple Compile within the C Programming forums, part of the General Programming Boards category; When I compile a simple program with GCC I get no errors and it runs fine When I compole the ...

  1. #1
    Registered User Bassglider's Avatar
    Join Date
    Nov 2007
    Posts
    32

    Xcode Apple Compile

    When I compile a simple program with GCC I get no errors and it runs fine

    When I compole the same simple program with Xcode (Command Line C) I get these errors:

    Warning: return type defaults to 'int'
    Warning: control reaches end of non-void function

    They do not stop the build from succeeding but I was wondering what I am doing wrong to make these errors happen. This code is from K&R

    Code:
    #include <stdio.h>
    
    main()
    {
            int c;
    
                    c = getchar();
                    while (c != EOF) {
                            putchar(c);
                            c = getchar();
                    }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    gcc will also complain.
    Code:
    $ gcc -W -Wall -ansi -pedantic  foo.c
    foo.c:4: warning: return type defaults to `int'
    foo.c: In function `main':
    foo.c:12: warning: control reaches end of non-void function
    > foo.c:4: warning: return type defaults to `int'
    In times past, not saying what type something was was the same as saying int.
    Nowadays, these "implicit types" are frowned on, and we say
    int main
    to be totally clear about it.

    > foo.c:12: warning: control reaches end of non-void function
    We should have said
    return 0;
    The warning is telling us that falling off the end of the function is going to return some kind of junk value.
    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.

  3. #3
    Registered User Bassglider's Avatar
    Join Date
    Nov 2007
    Posts
    32

    thanks

    thanks

    Do these new times == ANSI C?

    If so then why does K&R refer to their updated version as ANSI C?

    Thank you for the clarification

    Bassglider

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    > Do these new times == ANSI C?
    Yes.

    > If so then why does K&R refer to their updated version as ANSI C?
    Their new book (the ANSI-C one) came out in 1988 (20 years ago) at the very dawn of the ANSI era of C programming. Since then there has been a new ANSI-C standard (C99) which specifically removes "implicit int" as being valid C (in other words, it's been deprecated).

    Remember at the time most code would have made plenty of use of the "implicit int" rule, so even making it a warning right away would have generally annoyed everybody.

    Keen K&R users should make a note of this as well.
    http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html
    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 Bassglider's Avatar
    Join Date
    Nov 2007
    Posts
    32
    You are referring to prototypes correct?

    I am also just about to order Pratas book C Primer Plus as a book to accompany K&R. I believe K&R would be a good way to expand upon the details of certain subjects for greater understanding. This will be more third C book.
    Last edited by Bassglider; 12-09-2007 at 03:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 12:36 PM
  2. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 08:05 PM
  3. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 01:58 PM

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