MTG
But it is your doubt and i m clear one that
MTG
but its fine i will post
Vishal
Yeah
Vishal
Don't forget that
Cengizhan
It is also UB, how do you know that stackoverflow question will not be answered by Madhu? :)
Cengizhan
If you do not believe or convince yet from others, we are not here to make you convince.
Cengizhan
If you say that it is not UB, ok do it on your own thats all.
MTG
https://stackoverflow.com/questions/63147390/is-this-a-undefined-behavior-or-not?noredirect=1#comment111665427_63147390
MTG
You can track as much as you want
Vishal
You should have asked the other example as well
Vishal
Because you didn't agree on that as well
Vishal
I think you should include that
MTG
Read the answer also
MTG
yes
MTG
sure
MTG
Looks like another guy answered
MTG
🙂
MTG
That's fine 👍
Sorry
MTG
Sorry about gender not about the argument
Anonymous
One of my senior too said that question is not UB
As per him
g : stores base address
g[6] = *(g+6) it is 'o' 111
g[8]= 103
Expression is base address + 8 so answer is 1..
What should i consider?
MTG
g is pointer to char
MTG
MTG
yes
MTG
still we are
MTG
If I am wrong I will accept for sure
Anonymous
/get
Vishal
If I am wrong I will accept for sure
I don't know what someone has to do in order to prove to you whether something is UB or not...when the standard itself is not enough...one can only wonder
MTG
I m not getting where the standard says intermediate calculation values can't go out of bound
MTG
We get undefined behavior if we access the pointer
Vishal
You didn't agree to the other example being UB as well!!
MTG
and the pointer access takes place once the result is passed to the printf function
MTG
MTG
we just computed it
Vishal
4.3 has clearly said that the addition itself is UB
Vishal
Anonymous
Thank you very much!!
Anonymous
hi guys
Vishal
One interesting thing that his question has brought out is that even 'o' - 'g' isn't guaranteed to be 8 always
Vishal
So it's undefined anyways
Anonymous
please sand link of c# drage and drop software
MTG
here we are referring to ascii values right?
Vishal
Ohk...I missed that
Vishal
I guess if Bjarne Stroustroup will explain to him in person then he'll accept
Anonymous
Anonymous
One more doubt i have...
Question : predict output
#include<string.h>
#include<stdio.h>
int main()
{
char a = 30, b = 5;
char *p = &a, *q = &b;
printf("%d", p - q);
}
a) 1
b) Run time error
c) Compile Time error
d) Garbage value
Answer : a
Explanation given was difference between any two variables of same data type are always one
But i think explanation given is wrong as, as per my understanding pointer substraction gives how many such type data can be stored within those addresses..
Is it always one or my understanding is correct?
Vishal
Samarth
Vishal
Afair it's not guaranteed that individual stack variables will be next to each other
Anonymous
Vishal
Isn't that why it's UB?
Anonymous
So for such questions i should say answer is UB
Anonymous
Okay...
Understood!
Vishal
👍
Anonymous
Anonymous
Doing things on pointers like comparing their value is undefined behavior
Anonymous
Yeah... from now i will...
Anonymous
&a > &b for instance is undefined
Anonymous
Anonymous
@lightness_races_in_orbit do you see any UB here?
Anonymous
https://github.com/facebook/rocksdb/blob/d9d190742c0a8a3d5ff0b0867383bd38c1d0f5f0/db/db_impl/db_impl_secondary.cc#L115
Cengizhan
There is no UB.
Scriptern
/get programming books
olli
I m not getting where the standard says intermediate calculation values can't go out of bound
then learn to read the standard, if you can't fall back to the SO answer provided above.
The standard document talks about an "expression" which defines "the syntax, order of evaluation, and meaning of expressions. An expression is a sequence of operators and operands that specifies a computation. An expression can result in a value and can cause side effects." [expr]
Even to compute a temporary you make use of the additive expression and so the rules apply, and while it's most likely to work fine on most architectures you encounter, your compiler is allowed to emit all the code it wants, potentially even harmful one. So I would argue not to invoke UB.
Anonymous
/getfreeprogrammingbook
Anonymous
/getfreeprogrammingbook
Anonymous
Anonymous
For some reason if the last 2 conditions are swapped the UB disappears
Ajay
BTw, if 'o'-'g' isn't guaranteed to be 8 then using this in programs is UB. Isn't it?
Ajay
If the answer for my above question is yes, then encoding provided by the state govt. Isn't it like if you use the govt. provided encoding then it will always be UB?
Ajay
ok I get that it will surpass the valid bounds. So if it surpasses the bounds in some X character encoding and not in some other character encoding Y, then it's UB in X and not in Y?
Ajay
ok fair enough, makes sense.
Anonymous
@lightness_races_in_orbit ot, but are you https://stackoverflow.com/users/560648/lightness-races-in-orbit?
labyrinth
a quick question, if I run a hello world program, is the parent process of this process the init process with pid_t == 1?
labyrinth
i was asked in an interview about how to check if a program has successfully run and it is too quick that it finishes before you can check with top or htop
Anonymous