Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > why return causes an Illegal syntax??

Reply
Thread Tools

why return causes an Illegal syntax??

 
 
chump1708@yahoo.com
Guest
Posts: n/a
 
      01-17-2006
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....

 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      01-17-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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!"
 
Reply With Quote
 
 
 
 
chump1708@yahoo.com
Guest
Posts: n/a
 
      01-17-2006
I meant what does first part of the statement (main && argc) ?
main(argc-1, NULL) : return 0;
does...IGNORE THE PRESENCE OF return...

 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      01-17-2006
On 17 Jan 2006 07:15:34 -0800, in comp.lang.c , "(E-Mail Removed)"
<(E-Mail Removed)> 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 =----
 
Reply With Quote
 
chump1708@yahoo.com
Guest
Posts: n/a
 
      01-17-2006
Hey brother...chill off...All I am trying to do is learn the way you
experts think....Is it bad??

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-17-2006
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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


 
Reply With Quote
 
Ingo Menger
Guest
Posts: n/a
 
      01-17-2006

(E-Mail Removed) 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.

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      01-17-2006
Mark McIntyre wrote:
>
> On 17 Jan 2006 07:15:34 -0800, in comp.lang.c , "(E-Mail Removed)"
> <(E-Mail Removed)> 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
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      01-17-2006
On 17 Jan 2006 07:43:45 -0800, in comp.lang.c , "(E-Mail Removed)"
<(E-Mail Removed)> 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 =----
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      01-17-2006
On 17 Jan 2006 08:16:12 -0800, in comp.lang.c , "(E-Mail Removed)"
<(E-Mail Removed)> 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 =----
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Illegal Downloading causes DVD (deadly venereal disease) charlestruman@hotmail.com DVD Video 1 10-22-2007 11:03 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Postback causes 100=Continue, causes double download prompt? Xavier Osa ASP .Net 0 01-09-2004 11:17 AM



Advertisments