spot the difference
Spot the difference
Other urls found in this thread:
wdym one runs once and the other runs forever
oh whoops just saw the break;
Nope
>break;
-f
+whle{break;}
The asm instructions are different?
one's an if and the other's a while
.LC0:
.string "foo"
func:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], 5
cmp DWORD PTR [rbp-4], 9
jg .L2
mov edi, OFFSET FLAT:.LC0
call puts
.L2:
cmp DWORD PTR [rbp-4], 9
jg .L4
mov edi, OFFSET FLAT:.LC0
call puts
nop
.L4:
nop
leave
ret
if will print foo and move on
while will print foo then break out
the difference is the if statement has on less line of code.
Also why not use the ternary operator
>Also why not use the ternary operator
>using the ternary operator to perform actions
yikes
this, ternary conditions should not be used for control flow. Absolutely haram.
Because this is valid C, both are undefined behavior and therefore both blocks of code are equivalent to
, so there is in fact no difference.
first printf already caused side effect and thus second printf in while block runs in state with that side effect
Can you explain why?
You need int main for it to work, op
*slow claps in african
Fuck you man i just started "programming" an hour ago, to be honest it was used to return a value i think on the example given but they didnt say anything about that.
Any optimizing compiler worth shit will optimize away both the if and while and then merge the identical printf call into one puts() call
clear code virgin detected
makes me laugh when people try to micro optimize their code and they dont realize the compiler will just throw it out for it's own optimizations
I agree.
The other day I was thinking about designing an experimental programming language that only used loops.
But the loops would be self modifying (ie statements can be removed dynamically. Sometimes in loops you'll have a statement that only needs to trigger once, and then never again - we code in a way to avoid the situation where a condition is being checked unnecessarily, but with my theoretical design you wouldn't need to, since statements will be deletable from the loop.
Based
One is an if statement, while the other is a while loop.
Wow... I didn't know that Jow Forums is so much uneducated in the field of comp arch
Let's go.
First of all, if you compiler won't catch thie second case and turn it into the first then in any isa the loop will produce more instructions. In a risc isa, that's 2 more instructions, one jump for the break and another one at the end of the loop.
Let's see what will happen again if we won't get this shit optimized by our compilers.
First of all in many ooo cpus, intel and amd afaik, the second case will make the cpu IF stage to decode it and try to unroll it. Since late 90s many cpus have a module in the IF stage that picks
ARM high performance cores are also OOO you fucking autistic nigger dumb spic pajeet. Never leave ARM High performance cores out the discussion again.
This thing exists for many languages.
Hls synthesis treats everything as a loop with the appropriate II value. If it's not a loop, then II is -1, if it's a loop, then it runs the well-known SMS algorithm to determine the II and either create an fsm or unroll it.
This is a compiler approach, not a language one. You can write regular c/c++ code and the compiler does the job.
This is an intel patent, which I think that amd pays to use it, but a huge amount of arm ooo architectures don't have it because it is not good in terms of power consumption.
What incantation is this?
Result wise there is no difference
how much money you earned by being able to solve this and also how many printf programs you were commissioned to do?
If has no braces
second is better sir
while will print nothing at all
do while is executing statement at least 1 time then checking condition
while is checking condition first then executing statement, but statement has break in it, so statement will execute 0 times
Pajeet or bait?
Do us all a favor and never write code.
font rendering is too good for somebody retarded enough to still program in c.
>but statement has break in it, so statement will execute 0 times
weak bait
no difference because A = 5. So it's gonna print foo regardless.
don't bring in optimization crap because compiler would compile both of them to the exactly same assembly code.
underrated
This. CFG is identical in both cases
lolnope
godbolt.org
heard of compilers?
You might be right, i didn't read all that because it was 3 am and i wanted to sleep. interesting stuff
One's retarded and the other is fuck you!
>ternary operator
chads use &&
> (a < 10) && printf("foo\n");
wew
No difference there. Both just print "foo" once each.
>nop after branch target
Because it's not coincides.
^certified based
What theme
literally default vim syntax highlighting
does anyone have an actual answer
Yes, there are several in the thread already