• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

What does for (;;) mean?

AccruedExpenditure

Diamond Member
I'm confused on what for (;; ) just like that with no variables does... what does that do?

Also those voids are also throwing me off... any clues? Running it in the compiler with checks really hasn't helped me figure out whats going on =/

#include <stdio.h>

int main(int argc, char **argv) //declares an int argc, and a 2 dimensional char array argv
{
if (argc <= 1)
{
for (;😉
{
(void) putchar('y');
(void) putchar('\n');
}
}
else
{
for (;😉
{
int i;
for (i = 1; i < argc; i++)
{
if (i > 1)
(void) putchar(' ');
(void) fputs(argv, stdout);
}
(void) putchar('\n');
}
}
return (0);
}
 
The (void) for casting the return of putchar to void (unknown type), just like if you did (int) would attempt to cast to an int. If I recall putchar in some C environments returns an int indicating an error so casting to (void) would probably just allow the program to compile without you needing to assign the returned value to anything.

And yup, as above the for ( ; ; ) runs forever, maybe they should include a new loop in C#, you have for each, why not for (ever) {} 🙂 Can't remember the last time I used infinite loops though, dangerous habit. 🙂
 
Originally posted by: Snapster
The (void) for casting the return of putchar to void (unknown type), just like if you did (int) would attempt to cast to an int. If I recall putchar in some C environments returns an int indicating an error so casting to (void) would probably just allow the program to compile without you needing to assign the returned value to anything.

It's also possible that there are other tools running to check for common mistakes in the C code (lint, for example). One of the checks would be to see that return codes aren't ignored, so for example if a function returned an error code you could do something about it in the code. Casting the function to return void lets the tool know you really mean to ignore the return code. This is commonly done for cases like putchar, printf, and so on, where you only rarely get errors, and care about them even less frequently.

 
The winking smileys in the middle of the code crack me up. Someone needs to fix this stuff if they expect this programming forum to get popular.
 
Originally posted by: jalaram
Wouldn't

do { } while (true);

work the same? What the advantage/disadvantage of the for version?


yes, the same. same as

while(true)

too. no real advantage/disadvantage AFAIK. and i'm pretty sure they all get compiled/assembled into similar instructions.
 
Originally posted by: GoatMonkey
The winking smileys in the middle of the code crack me up. Someone needs to fix this stuff if they expect this programming forum to get popular.

When you reply to a message, there's a "Attach code" button. It brings up a new dialog that says:

Code Window [ CLOSE WINDOW ]

If you would like to insert raw code into your message insert it here, the html code will be stripped out, and spaces will be replaced with HTML spaces ( ).

The OP's code becomes:

 
There's also a "Do not parse emoticons" option in the full reply Window that isn't there if you just use the quick reply at the bottom of the thread.
 
And yup, as above the for ( ; ; ) runs forever, maybe they should include a new loop in C#, you have for each, why not for (ever) {} Can't remember the last time I used infinite loops though, dangerous habit.

Or they could not do that. What next you're going to want to have every variable have a damn $ in front of it.
 
Originally posted by: smack Down
And yup, as above the for ( ; ; ) runs forever, maybe they should include a new loop in C#, you have for each, why not for (ever) {} Can't remember the last time I used infinite loops though, dangerous habit.

Or they could not do that. What next you're going to want to have every variable have a damn $ in front of it.

You do realise that was a tad of sarcasm there.... I'm quite happy with C#, not sure I can say the same with with C# 3.0 with var types.

 
Originally posted by: Nothinman
Or they could not do that. What next you're going to want to have every variable have a damn $ in front of it.

Sigil's definitely make it easier to find variables in your code...

Good naming and syntax conventions work well too.
 
Originally posted by: Nothinman
Good naming and syntax conventions work well too.

No doubt, but I'd rather read $variable than intVarIable.

Both are quite simple to read.

I assume you are referring to Perl when you mention variables with sigils - unfortunately that language does not lend itself to readability.

Of course, the real problems only arise with programmers who have lousy programming habits.
 
Both are quite simple to read.

Yes, but StUdLyCaPs is damned ugly.

I assume you are referring to Perl when you mention variables with sigils - unfortunately that language does not lend itself to readability.

I assume so too, I was only commenting on smack Down's comment about the $.

perl's readability is what you make it, the only things that are a little complicated are the built-in variables with funky names like $_ but you can use the English module to let you access them with more readable names if you like and regexps but those are bad in any language.
 
Originally posted by: Nothinman
Both are quite simple to read.

Yes, but StUdLyCaPs is damned ugly.

I assume you are referring to Perl when you mention variables with sigils - unfortunately that language does not lend itself to readability.

I assume so too, I was only commenting on smack Down's comment about the $.

perl's readability is what you make it, the only things that are a little complicated are the built-in variables with funky names like $_ but you can use the English module to let you access them with more readable names if you like and regexps but those are bad in any language.

Well, when I said "both" I was assuming good naming conventions - anyone who writes variable names like you did in your example should be shot 😛

As I said before, unreadable code is the fault of the developer - I only meant that Perl makes it easier to write hard to read code, at least from what I've observed in practice.
 
Well, when I said "both" I was assuming good naming conventions - anyone who writes variable names like you did in your example should be shot

Well StudlyCaps is extreme but IMO CamelCase is just as bad. And the same goes for HungarianNotation that I always see in MS' crap.
 
Originally posted by: Nothinman
Well, when I said "both" I was assuming good naming conventions - anyone who writes variable names like you did in your example should be shot

Well StudlyCaps is extreme but IMO CamelCase is just as bad. And the same goes for HungarianNotation that I always see in MS' crap.

HungarianNotation is horrible, I agree.
 
Originally posted by: JustAnAverageGuy
iDontSeeWhatIsWrongWithCamelCaseICanReadThisJustFine.

besidesYouShouldntUseExcessivelyLongVariableNamesLikeThisAnyway

- JaAG

However, YSUTE is just as bad... 🙂

Bill

p.s. YouShouldntUseThisEither
 
Back
Top