Rakesh
Give features of C that are not in C++
Ludovic 'Archivist'
Rakesh
why?
This question was asked to me in a exam
abdisa
Give features of C that are not in C++
In C, you can use the register keyword to suggest to the compiler that a variable should be stored in a register instead of in memory. This can improve performance for variables that are frequently used. However, in C++, the register keyword is deprecated and has no effect on modern compilers. Instead, the compiler will automatically optimize the use of registers based on the code's needs.
Ziky
Give features of C that are not in C++
In C you can name your variable or function "class" 😁
\Device\NUL
The register keyword
afaik register keyword is removed on newer standard
Chat Boss
. sent a code, it has been re-uploaded as a file
\Device\NUL
This is undefined behaviour as range is uninitialized but you access its value
\Device\NUL
Also, Fix your indentation. It made people eyes hurt
\Device\NUL
int range = 0;
CALVIN
Libxl or libxml?
If the libxml can also be used to manipulate excel then it's fine
Aleksandr
Hello guys! I’d like to ask u a question. Is it worth trying anything new, for example C++? I learnt Python for 2 months, then it turned out kinda boring and decided to learn front end basic languages (html, css, js). I’ve been learning them for 6 months and now I think of changing the language because webdev became kind of boring for me as well. I assume that C++ will be amazing for me cuz it’s difficult and seems interesting to utilise. Just wanna try something new and make a decision what’s better for me. What do u think?
Ludovic 'Archivist'
afaik register keyword is removed on newer standard
Of C++, yes, but not in C (but in C it most of the time does nothing)
Ludovic 'Archivist'
Another example is the restrict keyword
Anonymous
Hi I have doubt
Anonymous
In c that
Anonymous
If whether we want to eligible for vote or not
Anonymous
By do while
Anonymous
How to do that ?
klimi
How to do that ?
You use if statement because while is a loop.
Anonymous
You use if statement because while is a loop.
She can do it using do while loop but if she does that it would stuck in the loop untill the input age is valid for voting
Anonymous
Or she can use break in loop to get out of the loop
GOPA
hi i would like to know which image library is best opencv or cimg
labyrinth
what will happen if I use thread local storage in another thread
Ziky
what will happen if I use thread local storage in another thread
I am not sure what do you mean with local storage but each thread has its own stack but have shared memory space so you can access to variable of any thread within single process.
klimi
She can do it using do while loop but if she does that it would stuck in the loop untill the input age is valid for voting
you can just use another bool variable, the thing is it doesn't make sense to use "while" as "if" if you have "if"
Anonymous
what will happen if I use thread local storage in another thread
A thread local storage variable is a named identifier that represents different variables in different threads. If you must access a thread local variable from another thread, then you must do it indirectly using pointers. But you have to be careful with the lifetimes and also with synchronisation which both defeat the purpose. So it is not a wise choice
klimi
Yes exactly 😅 Maybe she wanna try something new
i doubt that, it's probably some assigment/exam question
Anonymous
i doubt that, it's probably some assigment/exam question
Yeah N probably the assignment was to use the age validation system until the user wants to exist So maybe her teacher to use do while loop for that and she got confused
My Drive
Can any one exactly tell where do we make use of while loop
Jose
Can any one exactly tell where do we make use of while loop
When things tends to be repetitive, but we don't need a start condition neither an increment, such as for does
Jose
For example, in firmware, when we poll a data from a hardware doesn't have any interruptions. You must use a while instead the for as the usual approach to have an active waiting until the data comes to the device
Anonymous
Note that even access by pointer may not be possible, depending on the implementation. Implementations may have threads using different address spaces
Yeah that is correct. Not sure if there exist implementations however that do this. Maybe in the embedded world.
Саша
👋
Саша
i want to start c++ learn. do u know some good books for newbies?
Anonymous
Maybe BSDs
No. BSDs are POSIX compliant and they are required to stick to the requirement that threads share the address space of the process. FreeBSD and NETBSD do this. I am quite sure that OpenBSD does this too but I maybe wrong
Anonymous
No. BSDs are POSIX compliant and they are required to stick to the requirement that threads share the address space of the process. FreeBSD and NETBSD do this. I am quite sure that OpenBSD does this too but I maybe wrong
Unix has traditionally shared address space of the process with the threads (till SysV which is where BSDs branched from after the split with AT&T). So I doubt if they would have broken this compliance requirement. I will check the code and get back to you here shortly.
Anonymous
Unix has traditionally shared address space of the process with the threads (till SysV which is where BSDs branched from after the split with AT&T). So I doubt if they would have broken this compliance requirement. I will check the code and get back to you here shortly.
I checked the code for FreeBSD. https://github.com/freebsd/freebsd-src/blob/main/lib/libthr/thread/thr_create.c#109 Here when a thread is created, the create_stack function is called which creates a stack for the thread in the same address space as that of the process. So FreeBSD doesn't create different address spaces for the threads. Neither does NetBSD from my experience. I will check the code for OpenBSD and get back to you
Anonymous
I checked the code for FreeBSD. https://github.com/freebsd/freebsd-src/blob/main/lib/libthr/thread/thr_create.c#109 Here when a thread is created, the create_stack function is called which creates a stack for the thread in the same address space as that of the process. So FreeBSD doesn't create different address spaces for the threads. Neither does NetBSD from my experience. I will check the code for OpenBSD and get back to you
OpenBSD does fork when a new real time thread is created. So you are right regarding that. The address space for the thread is different from that of the process. https://github.com/openbsd/src/blob/master/lib/librthread/rthread_fork.c This is for real time threads however. So the requirements are different but I would take your suggestion at face value and assume that there are implementations out there that don't create threads in the same address space as that of the process. So I stand corrected. Just to be sure, I will check th code for non real time threads as well. Need some time to go through the source code to figure out that logic.
Anonymous
Anonymous
OpenBSD uses rthreads (not real time threads as I initially thought) an improvement over pthreads as suggested in the link above. Creating a thread calls rfork which creates a new address space for the thread and hence thread local variables will not be accessible using pointers.
Ludovic 'Archivist'
OpenBSD uses rthreads (not real time threads as I initially thought) an improvement over pthreads as suggested in the link above. Creating a thread calls rfork which creates a new address space for the thread and hence thread local variables will not be accessible using pointers.
Yeah, I think this is what I remembered, and why thread locals cannot be assumed to be accessible between threads in the standard. It makes thread local variables more optimized at the cost of a bit of kernel handywork when other memory mappings happen
Anonymous
Yeah, I think this is what I remembered, and why thread locals cannot be assumed to be accessible between threads in the standard. It makes thread local variables more optimized at the cost of a bit of kernel handywork when other memory mappings happen
Well I don't see why you wouldn't create a new process instead of a new thread when they are going to be as expensive. Atleast you will have more control with cgroups and stuff
Anonymous
The only advantage with this method is that it made kernel code a lot simpler. The only change required in the kernel code is to add a flag that flags a new process as equivalent of a thread in the parent process
Leovan
Why I can't use non const static class field as array size? I find answers like: because it is not const, but why I can use global/local variable as array size then? int size = 5; int array[size]; // is legal
Danya🔥
It's not legal C++
Leovan
You can't
But It's works on my compiler, I can create array using global/local variable for some reason
Danya🔥
But It's works on my compiler, I can create array using global/local variable for some reason
It doesn't mean it's legal C++ Variable length arrays are not part of the C++ Just add --pedantic-errors flag to your compiler CLI invocation and read the error
Danya🔥
Always compile your code with -Wall -Wextra -pedantic -Werror
Tokir0074
Ok
Leovan
It doesn't mean it's legal C++ Variable length arrays are not part of the C++ Just add --pedantic-errors flag to your compiler CLI invocation and read the error
Okey, how then compiler handle this case? int size; std::cin >> size; int array[size]; It's common for examples from guides :d
Danya🔥
Okey, how then compiler handle this case? int size; std::cin >> size; int array[size]; It's common for examples from guides :d
Don't read the guides that suggest doing it, the people who wrote them don't know what C++ is
Danya🔥
I already said that's called "variable length arrays"
Danya🔥
If you want to learn about it more, google it But don't use it in your C++ code
Leovan
Don't read the guides that suggest doing it, the people who wrote them don't know what C++ is
I mean why compiler can compile this? And it works without errors if VLA isn't part of C++
Danya🔥
I mean why compiler can compile this? And it works without errors if VLA isn't part of C++
Because GCC folks think that they're smarter than everyone else and introduced this compiler extension Mainly for backwards compatibility with C
Danya🔥
why you hate VLA?
Because it's stupid error-prone shit that was dragged to C++ world as if there's no other problems in C++ because of this "language" called C
Ehsan
Oh I didn't know it was not standard
Anonymous
Fr?
Sench
How to check the user enter exact username and password from database instead of login
Vlad
Wtf are you talking about?
Now I want kvass. What have you done?
Vlad
why you hate VLA?
Why won't you hate vla?
Vlad
It's literally alloca but worse
Vlad
Usage of VLA is questionable even in C
Vlad
Folks that use it never sanitize their inputs
Sench
Na i write html file like form,this login form it have username and password first another form it have pass and user name from the user and the data save in the database,the user use login option that pass and user name id exactly the same the user enter the first
Sench
Why