why return causes an Illegal syntax??

Discussion in 'C Programming' started by chump1708@yahoo.com, Jan 17, 2006.

  1. Guest

    main(int argc, char *argv[])
    {
    (main && argc) ? main(argc-1, NULL) : return 0; //line 1
    }

    1. Can I know why using return causes an illegal syntax...I guess it
    has something to do with command line arguments..
    2. can anyone explain the line 1?? its a bit confusing....
     
    , Jan 17, 2006
    #1
    1. Advertising

  2. Artie Gold Guest

    wrote:
    > main(int argc, char *argv[])
    > {
    > (main && argc) ? main(argc-1, NULL) : return 0; //line 1
    > }
    >
    > 1. Can I know why using return causes an illegal syntax...I guess it
    > has something to do with command line arguments..
    > 2. can anyone explain the line 1?? its a bit confusing....
    >

    1. No, it's because `return' is a statement, not an expression.
    2. Simple. Syntax error. Next?

    --ag
    --
    Artie Gold -- Austin, Texas
    http://goldsays.blogspot.com
    http://www.cafepress.com/goldsays
    "If you have nothing to hide, you're not trying!"
     
    Artie Gold, Jan 17, 2006
    #2
    1. Advertising

  3. Guest

    I meant what does first part of the statement (main && argc) ?
    main(argc-1, NULL) : return 0;
    does...IGNORE THE PRESENCE OF return...
     
    , Jan 17, 2006
    #3
  4. On 17 Jan 2006 07:15:34 -0800, in comp.lang.c , ""
    <> wrote:

    >main(int argc, char *argv[])
    >{
    >(main && argc) ? main(argc-1, NULL) : return 0; //line 1
    >}
    >
    >1. Can I know why using return causes an illegal syntax...


    The operands of the ternary operator must be of the same type, eg both
    numeric, both the same struct type, both pointers to the same type,
    both void, etc etc. "return 0" has no type and is not the same as the
    type of main() which is int.

    The correct way to write this (which is an example of a recursive
    main, and illegal in C++ by the way) ) is

    return (main && argc) ? main(argc-1, NULL) : 0;

    >has something to do with command line arguments..
    >2. can anyone explain the line 1??
    >its a bit confusing....


    Where do you get this rubbish? This is the third total nonsense bit
    of code you've posted. What are you trying to do?

    Also, when posting to CLC, you should post snippets which #include any
    relevant headers. In this case, you need something to define NULL.
    Mark McIntyre
    --

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Jan 17, 2006
    #4
  5. Guest

    Hey brother...chill off...All I am trying to do is learn the way you
    experts think....Is it bad??
     
    , Jan 17, 2006
    #5
  6. Mike Wahler Guest

    <> wrote in message
    news:...
    > Hey brother...chill off...All I am trying to do is learn the way you
    > experts think....


    What the experts think is that you need to read
    some C textbooks and learn how the language works
    instead of guessing.

    >Is it bad??


    Yes, I think your apparent method of learning C is
    quite bad.

    Also note that it's not usually a good idea to
    insult those who can help you.

    Mark might not be the best expert here (I doubt he'd
    make that claim), but imo he does have considerable
    C knowledge and can offer much help (if you don't
    drive him away, that is).

    -Mike
     
    Mike Wahler, Jan 17, 2006
    #6
  7. Ingo Menger Guest

    schrieb:

    > main(int argc, char *argv[])
    > {
    > (main && argc) ? main(argc-1, NULL) : return 0; //line 1
    > }
    >
    > 1. Can I know why using return causes an illegal syntax...


    Yes you can. Just learn C syntax.

    > 2. can anyone explain the line 1?? its a bit confusing....


    Since it's not C, there is nothing to explain.
     
    Ingo Menger, Jan 17, 2006
    #7
  8. pete Guest

    Mark McIntyre wrote:
    >
    > On 17 Jan 2006 07:15:34 -0800, in comp.lang.c , ""
    > <> wrote:
    >
    > >main(int argc, char *argv[])
    > >{
    > >(main && argc) ? main(argc-1, NULL) : return 0; //line 1
    > >}
    > >
    > >1. Can I know why using return causes an illegal syntax...

    >
    > The operands of the ternary operator must be of the same type, eg both
    > numeric, both the same struct type, both pointers to the same type,
    > both void, etc etc.


    Assuming that you mean the two rightmost operands,
    if either of the two right most operands
    is a null pointer constant, or pointer to type void,
    then the other operand may be a pointer to a different type.

    > Where do you get this rubbish? This is the third total nonsense bit
    > of code you've posted.


    I've noticed that too.

    --
    pete
     
    pete, Jan 17, 2006
    #8
  9. On 17 Jan 2006 07:43:45 -0800, in comp.lang.c , ""
    <> wrote:

    >I meant what does first part of the statement (main && argc) ?
    >main(argc-1, NULL) : return 0;


    its a ternary operator, equivalent to if... then... else... endif

    if (main && argc)
    main(argc-1, NULL):
    else
    return 0;

    except that it has different syntax rules.

    >does...IGNORE THE PRESENCE OF return...


    but you did ask about that bit
    Mark McIntyre
    --

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Jan 17, 2006
    #9
  10. On 17 Jan 2006 08:16:12 -0800, in comp.lang.c , ""
    <> wrote:

    >Hey brother...chill off...


    Sure, if you promise to start learning properly and use a book. You
    cannot learn programming from usenet.

    >All I am trying to do is learn the way you
    >experts think....Is it bad??


    Learning the way we think, by posting garbage posts?

    Well, you're going to achieve that, because most of us are probably
    now thinking "this chump1708 is a complete idiot".

    Mark McIntyre
    --

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Jan 17, 2006
    #10
  11. On Tue, 17 Jan 2006 16:25:14 GMT, in comp.lang.c , "Mike Wahler"
    <> wrote:

    >Mark might not be the best expert here (I doubt he'd
    >make that claim),


    For the record, theres absolutely no way I'd do that. :)

    Mark McIntyre
    --

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
     
    Mark McIntyre, Jan 17, 2006
    #11
  12. Flash Gordon Guest

    Mark McIntyre wrote:
    > On Tue, 17 Jan 2006 16:25:14 GMT, in comp.lang.c , "Mike Wahler"
    > <> wrote:
    >
    >> Mark might not be the best expert here (I doubt he'd
    >> make that claim),

    >
    > For the record, theres absolutely no way I'd do that. :)
    >
    > Mark McIntyre


    For the record, this Mark wouldn't either. :)
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, Jan 17, 2006
    #12
  13. Chuck F. Guest

    wrote:
    >
    > Hey brother...chill off...All I am trying to do is learn the way
    > you experts think....Is it bad??


    Now this sort of rudeness is what will get you plonked.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
     
    Chuck F., Jan 17, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xavier Osa
    Replies:
    0
    Views:
    634
    Xavier Osa
    Jan 9, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    895
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,949
    Smokey Grindel
    Dec 2, 2006
  4. Andreas Leitgeb
    Replies:
    0
    Views:
    452
    Andreas Leitgeb
    May 15, 2009
  5. Good Night Moon
    Replies:
    9
    Views:
    283
    Rick DeNatale
    Jul 25, 2007
Loading...

Share This Page