I'm bored, go argue about this

I'm bored, go argue about this

Other urls found in this thread:

stackoverflow.com/questions/24886/is-there-a-performance-difference-between-i-and-i-in-c/24887#24887
stackoverflow.com/questions/13615243/which-of-the-following-combinations-of-post-pre-increment-operators-have-undef/13615797#13615797
twitter.com/AnonBabble

What's the argument... After and before?

It doesn't really matter which, but very occasionally you need to change.

Its a matter of when you decide to increment the value. Nothing to argue about. You can do it either before or after the value is returned.

Only in java though am I right?

As a non-programmer, let me just say: ++i seems the best. :-)

Preincrement is more efficient, it doesn't create a temporary variable.

>black bars on the edges
>yellow rectangle doesn't even reach the black bars
>comic sans
What program did he use to make this fucking piece of shit?
Maybe in the 1990s dear.

Doesn't work in python...I only know python.

++i is more efficient in general. You can easily see this in C++ when overloading the prefix and postfix operators. The overloaded postfix operator requires an additional object be created, and the value be returned by value instead of reference.

Whatever though

>What program did he use to make this fucking piece of shit?
Probably Paint if we're being serious

This. Postfix is practically universal.

Not sure about C++, but in C there is literally no difference between the two because of how sequence points work.

++i is faster than i++

They actually compile to the same assembly in both C and C++. GCC is smart enough to notice when does it need to perform the increment at O3, so using either with equivalent code gives well, equivalent results.
As an example:
#include
#include

#define MAX 10

int main(void)
{
for (int i=0; i

Any modern compiler of any proper language makes it irrelevant. If you think it matters, question your life choices.

They're two different things.

When you use them in a for loop like that then they will work the same because that statement is called at the end of each loop.

I use PHP because I am a shitter but consider the following and what the output will be.

As a rule of thumb I just use prefix increment.
Too slack to care about posting the difference, have a look on stack overflow if you're wondering, but if you don't know the difference you're probably a beginner programmer or just shit.

Moving things around so the compiler doesn't inline everything, it first stores c*2 in the first calling register, before incrementing the value.

For funsies printing in a loop in Java also had the same bytecode for both styles.
class Test {
public static int MAX;

Test();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":()V
4: return

public static void main(java.lang.String[]);
Code:
0: iconst_0
1: istore_1
2: iload_1
3: getstatic #2 // Field MAX:I
6: if_icmpge 22
9: getstatic #3 // Field java/lang/System.out:Ljava/io/PrintStream;
12: iload_1
13: invokevirtual #4 // Method java/io/PrintStream.println:(I)V
16: iinc 1, 1
19: goto 2
22: return

static {};
Code:
0: bipush 10
2: putstatic #2 // Field MAX:I
5: return
}
Ultimately it's a matter of showing intention I guess.

For there to be a difference you need to combine it with another operation so they are done at the same "time".

Like for my example the output is 0 4, because for the first one
$p = $c++ * 2;
it effectively does
$p = $c * 2; $c += 1;
and for the second one
$d = ++$c * 2;
it effectively does
$c += 1; $d = $c * 2;

As long as the i++ or ++i is on its own there'll be no difference in how it is handled. It needs to be part of a larger operation.

Should I tell my professor about this?
I already pointed out to him there's technically another smart pointer after he asked himself if there was and I get the feeling he doesn't like being corrected

Assuming you just want to do an increment and don't care which order,
If primitive, i++.
Otherwise, ++i.

There is no argument.

I've never seen "++i" in real world

>It doesn't really matter which
brainlet detected
i++ have to create temporary copy of i in order to return it before incementing which results in less efficiency

Modern compilers don't give a shit about this.

stackoverflow.com/questions/24886/is-there-a-performance-difference-between-i-and-i-in-c/24887#24887

depends on the use case.
For general purpose incrementation ++i is better as it just increments it.
i++ returns a new instance of i and then increments it.
both have different use cases.

Do you also ask your mom not to pick up the phone when you're doing something important online, retard?

Get with the times.

Why can't it just return i, then increment it?

Came into this thread thinking

>this'll never take off, no one would sperg about this

I underestimate Sup Forums yet again.

++i, because other unary operators are prefix (-, +, *, &, ~, !)

Both are shit. They are to terse, hide side effects and give rise to funny undefined behaviours like:
int k = i++ + ++i;

To use them safely, you have to reason about sequence points and all that jazz, just to fucking increment numbers.

why hasn't a language come up with a better way of incrementing then

hmm I haven't had to do this in a long time, it's been years, since i used a higher order style with recursion, even in C.

Just write "i += 1;". It has none of those problems.
The problems start by rolling incrementing into an expression.
There are plenty of languages that don't do this i++, ++i nonsense.

int k = (i += 1) + (i -= 1);
k += (k -= i);

what does k equal to fagboi

You are doing the same thing I complained about.
You rolled an increment operation, which should be its own statement on its own line, into an expression.

i = i++ - --i
what will happen?

who the fuck writes i++? lmao

At a guess, i = 2

To everyone itt who says the compiler will optimise away i++: this is only true for primitives. If you overload the ++ operator, there's nothing the compiler can do.

So if you want, you can default to i++ for primitives and ++i for user-defined types. But it's a lot easier to just use ++i by default whenever you don't actually need postfix, and not think about it.

k = 2i + 1
i = i + 1
Am I wrong?

> still using ++
Swift is the superior programming language, and they fucking dropped this abortion, the best way to do it is:
i+=1

>Paint
"hqdefault.jpeg"
It's a youtube thumb.

>mutable objects
Begone, pajeet.

And some people think /k/ is the easiest to troll.

i just don't care

99.99% of people who do "i++" actually want a "++i"
true fact
and it may avoid same obnoxious pitfalls like

>which results in less efficiency
you're the brainlet here

yes

i = i + 2, obviously, I'm a retard.

no, the whole point is that the line:
int k = i++ + ++i;

Is undefined behaviour. Your compiler is pretty much allowed to what it wants.
In a sense, all values for "k" and "i" are wrong.

Yeah, because no CPU architecture in the world has instructions with support for post increment.

Why would it be undefined? I am not arguing with you, I just don't understand why would something like this be different across different compilers for the same language?

Simply there are no guarantees in the standard, the same way the signed integer overflow is undefined because two's complement behavior is not guaranteed and architecture dependent, unless you use the inttypes.h fixed size integer types.

>native data type
>object
>>pajeet

stackoverflow.com/questions/13615243/which-of-the-following-combinations-of-post-pre-increment-operators-have-undef/13615797#13615797
This explains it better than I can.

Pretty much this. Sup Forums is the only place where it seems a large portion of people do prefix increment. Postfix is standard in most learning texts, particularly the major ones (K&R, for instance).

>worst answer at the bottom is written by a random pajeet
Like clockwork

Everything is an object.

GHCi, version 8.0.1
i = 1
i++
:4:4: error: parse error (possibly incorrect indentation or mismatched brackets)

It's not about speed lad
It's about consistency
If you just want it incremented it's better to use ++i
If you want to use it THEN increment, use i++

you're talking about an optimization that's so small it's not even worth doing. pre optimization is the root of all evil. If you're having memory or speed issues in your program, chances are it's not the i++ that's your issue.

>stackoverflow.com/questions/24886/is-there-a-performance-difference-between-i-and-i-in-c/24887#24887

For primitive types this might not matter, however if you are using an iterator, especially one with non-trivial construction/destruction this actually might matter.

you pajeet, you're supposed to be using at&t syntax, faggot.
I mean I can't read shilltel syntax and it's your fault.

Are you really using this stackoverflow link as your arguement you dumb fuck

Not the user you are replying to but how about you actually disprove it instead of going
>b-b-but its stackoverflow ddumb fuck

op you're retarded

int temp ;
int temp_2 ;

temp = I ;
temp_2 = 1 ;
I = temp + temp_2 ;

dest dest, fite me.