Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@irene I don't think that's undefined? Terrible code yea, but I'm pretty sure that's defined behavior
-
olback107945yDumb question because you would never write code that looks like this unless you're an absolute fucking idiot.
Edit: Sorry not sorry if I offended someone. -
SomeNone7115yLooks like from an interview all right, or some such. Anyway… output is:
10 11 20 10
Variable i gets initialized to 9, then increased, so it prints 10.
New scope is declared with a variable i that shadows the i from the outer scope; the inner i is set to 11, so it prints 11.
Variable i is decremented, making it 10, then added to itself, making it 20, so it prints 20.
Inner scope is closed, next access to i is the original outer one, so it prints 10.
He/She/It who/which understands scopes and basic C operators should get this right without even having to type, compile, and run this program. -
I am confused. I thought I would learn some new WTF thing about programming but I was wrong.
I failed ya all guys..
I failed to understand the point...
¯\_(ツ)_/¯ -
I support that line 14 is undefined behaviour because there's no sequence point between two accesses to the same scalar that is subject to a side effect.
-
SomeNone7115y@Fast-Nop Maybe, maybe not, I don't have time to read the specs right now… and now that I think about it, it is not quite clear whether the final addition is to the value of i before or after evaluating the right-hand side. If the specs don't have an aswer (or explicitly state that the behaviour is undefined), then it is indeed undefined.
-
@irene That's why, at least in C++, it's not uncommon in company coding standards to forbid any use of templates except the ones the STL already provides.
-
@irene That is what I thought at first.
But usage is SOOOO simple. Basically this allows me to simplify Entity framework code soso much ! -
@irene True. And I try to avoid it as much as possible. But this one, saves around 5000 lines of code (Whole app combined)
Related Rants
This is the basic program of C Language. What will be the output?
question
developer
python
programming
java
c++
coder
c
programmer