[–] theNakedNecromancer 0 points 2 points (+2|-0) ago 

As long as you're not screwing with the way C performs the action, I don't see why not. In other words: x++ and ++x are two completely different functions.

So, doing x *= ++i will perform:

x = x * (i + 1)

But, doing x *= i++ will act like:

x = (x * i) + 1

Beyond that, style is up to you. Most C-coders (and style guides) won't want whitespace around the variable, or between a variable and increment operator. But, if it's code just for you, who cares?

[–] J_Darnley 0 points 1 points (+1|-0) ago  (edited ago)

No it won't. The second is equivalent to:

x = x * i;
i = i + 1;

a++ is "read then increment" whereas ++a is "increment then read".

[–] Rakosman 0 points 1 points (+1|-0) ago 

I prefer to always use the postfix operator. To me it is more important to have easy to read code than succinct code, and I also think the prefix one is uglier, so there's that.

[–] WhiteMakesRight 0 points 0 points (+0|-0) ago 

But they're different operators, with different semantics......

[–] Rakosman 1 points -1 points (+0|-1) ago 

Yes, and?

[–] TheBuddha 0 points 1 points (+1|-0) ago 

https://softwareengineering.stackexchange.com/questions/223313/style-guide-for-c

However, it's more important to be consistent. Whatever you go with, be consistent.

[–] WhiteMakesRight 1 points -1 points (+0|-1) ago 

Consistency is irrelevant when you're talking about two different operators with different semantics though. Use the one you actually need.

[–] BitterBiped 0 points 0 points (+0|-0) ago  (edited ago)

The post ++ is better than the pre ++. Because if it weren't Stroustrup would have called it ++C and not C++, kappa.

[–] Almond87 0 points 0 points (+0|-0) ago 

I suggest you think which the output is going to be and then compile it and run it to see by yourself. Hope i helped a bit


masterseo

[–] WhiteMakesRight 0 points 0 points (+0|-0) ago 

Who cares. CoffeeScript took "nice" syntax to it's logical conclusions and ended up with the ugliest and most unreadable language ever created.

[–] RicardoBronson 0 points 0 points (+0|-0) ago  (edited ago)

They both suck because of unspecified behavior in some situations. And usually when you want it least. Like for loops using pointers. Trust me, just say "counter += 1" and you will never have to know the pain EDIT: Actually why bother trusting me, do a search: https://www.google.com/search?hl=en&q=postfix%20increment%20unspecified%20behavior

[–] WhiteMakesRight 1 points -1 points (+0|-1) ago  (edited ago)

The operators have nothing to do with the unspecified behaviour you're talking about though -- they're just a succinct way to trigger it. What's actually unspecified is the order of evaluation of function arguments -- which is something you should be aware of even if you never use increment operators.

Not using increment operators at all is a typical example of "scarring on the first cut". If you're going to write software in C, rules-of-thumb will only get you so far. At some point, you have to read and understand the specification in depth.

[–] RicardoBronson 0 points 0 points (+0|-0) ago 

I take more of a "when in doubt, do it in python" approach because life is just too short to spend on specifications :) But I'm sure you're right

[–] danielabrown 0 points 0 points (+0|-0) ago 

the both are perfect. once they are well utilized properly. normally on hackrypton.com there are so many tutorials that will help in securing things like that easily

load more comments ▼ (4 remaining)