Thread: doubt

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    1

    Exclamation doubt

    i got some basics right and i made this program in turbo C:

    #include <stdio.h>
    main()
    {
    printf("Hi");
    }


    ok, when i compile this, i get a warning saying the function should return a value...what does this mean??

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It means that main is a function, which returns an int. You should be doing:
    Code:
    int main( void )
    {
        printf("Hi");
    
        return 0;
    }

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    and try using a better compiler not the outdated compiler TURBO C

    you could try dev-c++ compiler

    ssharish2005

  4. #4
    Java and C newbie Xero's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    21
    Although in Turbo C v2.01, that program is running OK.
    Last edited by Xero; 08-19-2006 at 03:36 AM.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Just because it's "simple code" doesn't mean you should ignore compiler warnings. Prior to C99, you were allowed to leave off the return type for main, you are no longer allowed to do this. In this case, they luck out by having a crappy old compiler. In the future, they may not be so "lucky". Thus, you should begin to develop good practices early.

    If you're going to take the lazy way out all the time, don't bother programming. Or at least, don't bother posting here, because I don't want to have to correct all of your crap you vomit up here.

    They also luck out here because they're in main, which is the only function for which the language defines what happens when you omit the return statement. Any other non-void function which reaches the end, and doesn't have a return statement, has undefined behavior for what it actually returns.

    In short, you may be able to get away with being a pile of crap, but that doesn't mean you're good for anything other than fertilizer. It also doesn't mean anyone will want to be around you.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Java and C newbie Xero's Avatar
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    21
    Quote Originally Posted by quzah
    Just because it's "simple code" doesn't mean you should ignore compiler warnings. Prior to C99, you were allowed to leave off the return type for main, you are no longer allowed to do this. In this case, they luck out by having a crappy old compiler. In the future, they may not be so "lucky". Thus, you should begin to develop good practices early.

    If you're going to take the lazy way out all the time, don't bother programming. Or at least, don't bother posting here, because I don't want to have to correct all of your crap you vomit up here.

    They also luck out here because they're in main, which is the only function for which the language defines what happens when you omit the return statement. Any other non-void function which reaches the end, and doesn't have a return statement, has undefined behavior for what it actually returns.

    In short, you may be able to get away with being a pile of crap, but that doesn't mean you're good for anything other than fertilizer. It also doesn't mean anyone will want to be around you.


    Quzah.
    Thanks for that.

    (First post edited to avoid further confusion, and bad programming practices.
    credit for quzah for reminding me 'bout that.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doubt in pointer.
    By shwetha_siddu in forum C Programming
    Replies: 5
    Last Post: 03-21-2009, 01:28 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Doubt abt Storage!
    By kalamram in forum C Programming
    Replies: 1
    Last Post: 04-21-2006, 05:30 AM
  4. arrays doubt
    By j0nnyX in forum C Programming
    Replies: 4
    Last Post: 11-20-2004, 01:10 PM
  5. Greatest C++ Doubt
    By vasanth in forum C++ Programming
    Replies: 15
    Last Post: 02-28-2002, 04:41 AM