[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

>S++ or S=S+1, which can be recommended to increment the value

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 18
Thread images: 2

File: 1314969009035.jpg (72KB, 628x473px) Image search: [Google]
1314969009035.jpg
72KB, 628x473px
>S++ or S=S+1, which can be recommended to increment the value by 1 and why?

>S++, as it is single machine instruction (INC) internally.
>>
>not using ++S
>>
>>56233272
That's a compiler's work.
Just write S = S + 1 in a higher language.
>>
>>56233291
S += 1
>>
>>56233272
>This retardation is on TWO websites
>>
>>56233291
>not knowing the 2 are different
>>
>>56233403
this, I like this more
I only use python though
>>
>>56233291
best
>>
>>56233272
Who gives a shit. Did you just learn how to program?
>>
>S++
>single machine instruction

lmoa, in what fucking world?
>>
File: operations.png (14KB, 891x380px) Image search: [Google]
operations.png
14KB, 891x380px
>>56233272
Does this answer your question?
If S is a primitive type and you don't care for the expression value, the compiler will generate identical code for all expressions.
>>
>>56233964
I didn't have a question...
>>
>>56234013
There's a question mark in your post, so yeah you did ask a question.
>>
>>56234047
I copied it from a website because it's stupid
>>
>>56233272
The compiler should be smart enough to optimize it.

I'm NOT sure how it would handle something like
while true
print array[i++]

though.

>>56233729
Most instruction sets include an increment instruction, which they should be able to use if the variable is already in a register.
>>
>>56234430
why are you not sure?
>>
>>56235944
Because I'm pretty sure most instruction sets can't read a value from an array, pass it to a function, and increment the array index in a single instruction. Incrementing a value is much simpler, taking only one instruction if it's already in a register.
>>
>>56236819
It should do it exactly as you described. There's no way that would just be one instruction.
Thread posts: 18
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.