Amstrong
ok
Dima
lool
Dima
bruh
Artöm
MALIK AMIR
visual studio
Link please?
Artöm
Link please?
https://visualstudio.microsoft.com/
MALIK AMIR
MALIK AMIR
What?
Tell me current version
MALIK AMIR
Artöm
16.5
MALIK AMIR
16.5
Thanks
Anonymous
never use gets it is deprecated. use fgets instead. whenever you need to use scanf/fscanf for strings, ALWAYS specify size! scanf(" %49s %c %c", s, &a, &b);
Asdew
fscanf is safer than scanf
I know this is old, but why?
abuyuusuf
Hi every one. Any open sourcr library for unit testing c++?
Anonymous
it is undefined behaviour that you MUST insure that your program will never trap in such behaviour (that's a bug in your program). But it is also a security problem. When you allow to an unknown stream to overwrite parts of memory like stack, it might lead to remote code execution vulnerability in your program
Anonymous
It can rewrite return address in stack for example
Anonymous
But it's kinda hard to achieve this with modern compilers, your program will crash in most cases
Anonymous
So You don't have enough knowledge to understand how this works
Anonymous
when you call a function, address to current position will be stored on stack. when you return from that function, processor will check the return address to find out where it was
Anonymous
anyway, security problem or a simple crash: undefined behaviour = bug and bugs should be fixed
Anonymous
yes, that has a defined behaviour: returned pointer is NULL or a memory with at least 10 valid bytes
Anonymous
Ask the person you've heard this from
Anonymous
It's bad in C++, not C
Nameful
It's bad in both, just that you have no better alternative in C :^)
Nameful
Why is this bad in C? :)
Why is it bad in C++?
Anonymous
Why is it bad in C++?
Because it uses raw pointers and malloc :)
Nameful
It's no better there
Anonymous
So does C
Raw pointers and malloc are not bad in C
Nameful
Raw pointers and malloc are not bad in C
What is the difference between them in C and C++?
Nameful
I mean, it depends on how you see it. By convention it's definitely not bad in C as that's what you do there (unlike in C++), but they are just as unsafe in C as they are in C++
Anonymous
What is the difference between them in C and C++?
Raw pointers in C++ are bad practice as a lot of other C good practices are bad in C++
Anonymous
You need to get some basics
Nameful
Raw pointers are inherently unsafe
Anonymous
Pointers themselves are unsafe You can shoot your knee easily
Nameful
RAII makes them easier to manage but they're still unsafe
Anonymous
RAII makes them easier to manage but they're still unsafe
He cannot understand this right now He has not enough knowledge rn
András
Int* fn() { int a = 5; int *b = &a; returb b; } What should be returned?
András
Yes So, and it's only 1 case where you make UB by returning pointers, and here is so much more
András
??
András
Okay int* res = fn(); int a = 0; int b = 0; int d = 0; print(*res)
András
No. You get pointer to 5
Anonymous
that's an undefined behaviour and definitely a BUG
Nameful
because you were lucky nothing else had been written there yet
András
Yep
And I try to show to @bumpfdp how is it caused
András
Yes
Nameful
it means that there's no guarantee that it will behave the same across compilers and systems yes
Nameful
it might be the same, but might also not be
András
András
https://t.me/programminginc/268328 did you run this code?
Anonymous
not exactly
András
Yes and no. Depend on UB
Anonymous
undefined behaviour = BUG
Anonymous
undefined behaviour = BUG
out of scope of C programming language
András
undefined behaviour = BUG
undefined behaviour is a feature😂😂
Anonymous
there are different result from C instructions: well-defined = no problem implementation-defined = read compiler document undefined = it might kill you or your family implementation-defined value = it doesn't kill you, but you have to read compiler documents to use resulted value undefined value = it doesn't kill you, but you may never trust resulted value
András
Create array for 100 elements, where every element is 0
~
Hi guys, may I ask you something not really close to C/C++?
manas
Undefined behaviour means that there is no expected behaviour defined by the standard, so anything can happen when UB code runs
jayaa
Hey guys, I am facing a problem with code blocks!
jayaa
It's throwing an error when I try to compile the programme. It's like, environment error can't find executable compiler....
jayaa
Can anyone solve my problem!!!
Anonymous
snprintf is better
Anonymous
because it has a defined behaviour on long strings: char buf[80]; snprintf(buf, sizeof(buf), "%s%s", a, b);
Anonymous
they are similar. _s functions are better
RINTO
/rules
RINTO
/rules
Anonymous
it has lower max value: RSIZE_MAX <= SIZE_MAX
Anonymous
it has lower max value: RSIZE_MAX <= SIZE_MAX
also it is not in C99, it is newer
Anonymous
AFAIK, only microsoft compiler does that. other compilers have different front end: gcc, clang for C g++, clang++ for C++
Dima
perhaps