Nobody🪲
I have tried in this way
klimi
klimi
what is the use of (int) or the (int*) before malloc?
\Device\NUL
\*test \*
Ольга
No it's like T9
Whem I copy to the grup, in my cod it is look like int 2star а (int 2star ) star is *
Nobody🪲
How can i solve this with conditional operator
klimi
\*test \*
even **test is ok, you need a pair of them
\Device\NUL
even **test is ok, you need a pair of them
I wrote markdown on github i escape asterisk using / . I think it would work but it isn't
klimi
this is not markdown
\Device\NUL
this is not markdown
But i heard Telegram using markdown formatting 🤔
klimi
# Heading 1
klimi
:)
Ольга
Ah, sorry
I need to apologize for that
\Device\NUL
# Heading 1
Only for bold italic underscore monospace and strikethrough i think
klimi
Only for bold italic underscore monospace and strikethrough i think
then it is not markdown... you could say it is markdown-like but... it is not markdown
Ольга
Ольга
You will have to free the individual elements of the array first and then you have to free the array itself.
The array itself I understand how to release, but the elements are not very much
klimi
what elements?
klimi
you have done 1 malloc, so you need to do 1 free (oh right, i didn't see the another malloc, you need to free that too)
Vlad
The array itself I understand how to release, but the elements are not very much
in the reverse order int** arr = malloc(N * sizeof(*arr)); for(int i = 0; i < N; ++i) arr[i] = malloc(M * sizeof(*arr[i])); for(int i = 0; i < N; ++i) free(arr[i]); free(arr);
Anonymous
The array itself I understand how to release, but the elements are not very much
For each array element you have to do a free(array[ i ]). And for the array, free(array)
Rajeev
vector <int> :: iterator IT; Why we use :: Why don't '.'
Anonymous
vector <int> :: iterator IT; Why we use :: Why don't '.'
Because iterator is a typedef or an alias. Not a member. You use the . operator to access members. You use :: to specify scope.
Vlad
And :: is a namespace resolution operator
Vlad
Thank you very much that is what I not understand. Thank you
In general there's a rule that destruction must be in the reverse order of construction. Construction goes from top to bottom. And destruction from bottom to top(smallest objects destroyed first)
Anonymous
In general there's a rule that destruction must be in the reverse order of construction. Construction goes from top to bottom. And destruction from bottom to top(smallest objects destroyed first)
Actually your example code also should do it. Your for loop should be for (i = N-1; i >= 0; --i) But this is not a problem. Usually it can be a problem if objects share state which is why the standard library containers do it that way.
Anonymous
If I recall correctly delete[] does do that from N-1 to 0, doesn't it?
I am talking about the individual frees (i.e freeing of the elements in the array) in your example code. free(arr[ i ]) should be in the reverse order. If you allocate arr[1] before arr[2], you should ideally free arr[2] before arr[1].
Anonymous
If I recall correctly delete[] does do that from N-1 to 0, doesn't it?
delete[] frees the array. If the individual elements themselves allocate memory on heap, then you need to delete them separately in the reverse order.
Vlad
If I recall correctly delete[] does do that from N-1 to 0, doesn't it?
If the value of the operand of the delete-expression is not a null pointer value, the delete-expression will invoke the destructor (if any) for the object or the elements of the array being deleted. In the case of an array, the elements will be destroyed in order of decreasing address (that is, in reverse order of the completion of their constructor; see 12.6.2).
Vlad
Yeah pretty much so
Anonymous
If the value of the operand of the delete-expression is not a null pointer value, the delete-expression will invoke the destructor (if any) for the object or the elements of the array being deleted. In the case of an array, the elements will be destroyed in order of decreasing address (that is, in reverse order of the completion of their constructor; see 12.6.2).
This is freeing of the array itself. I specifically am talking about the case where each individual element also is pointing to dynamically allocated memory using raw pointers. If your array is an array of shared_ptr, then yes delete[] would do the needful. I am talking about your specific code.
Vlad
Although it might be an issue if you have a custom allocator that relies on that or smth
Anonymous
Ideally yes. But free doesn't have a side-effects like a destructor does. So your pc probably won't catch fire if you free in ascending order
Well I said it won't be a problem unless you share state in which case it will definitely be a problem. Since you brought up the topic of freeing in the reverse order, I pointed out that your code could also do it.
Luis
Hello friends, I hope you are all well. I'm going to ask you a question that I know is typical of people without programming knowledge, but let me explain the context. I already know programming in PHP and JavaScript, also in C and C++ although I am a beginner in these two. Now, at the university I must focus on one of the two, and I ask you this question so that it can be answered from a personal point of view, which one would you focus on? , C or C++ and why? Sorry if my english it's not perfect.
jary
very good,very good👍
Luis
Your English is ok
Thanks you, it's good to know it. I'm learning english too. University, work, english, I'm gonna be crazy xD.
Danya🔥
You should choose C++, here is why: 1. C++ is more mature and has a better ecosystem 2. С++ offers more jobs
Danya🔥
3. С++ is more fun to use :)
Luis
c++ is harder
I do not have doubt of this. But it has several advantages. And you can even do things that can also be done in C. Not all of course.
Luis
> Not all of course. This is not true
Really? Oh, well this is even better.
Danya🔥
4. Once you know C++ enough, it's easier to use, read and maintain
Luis
Thanks for the help
Anonymous
Does anyone write the c++ with the feature modules?
Anonymous
Does the clion support modules?
klimi
I do not have doubt of this. But it has several advantages. And you can even do things that can also be done in C. Not all of course.
Well of course. But c has less stuff, c++ has more... Choose your poison. I choose C for something and C+j for something else
Hades
I'm unable to understand this pointer, any good resources?
Anonymous
Does the clion support modules?
CLion is an IDE. The question of support for modules is dependent on the underlying compiler. As of now only VS 2022 supports all PRs on Modules. G++ supports a majority of it and Clang is yet to implement 4 PRs. If you are going to use your own modules, you are good to go with any of these compilers. If you are going to be dependent on std modules, then your only choice is Visual Studio.
Danya🔥
Maybe he asks about support in cmake
Danya🔥
Or by static analyzer built-in to Clion
Danya🔥
Or by static analyzer built-in to Clion
Which is a custom analyzer and a custom-made clang-tidy
Anonymous
Maybe he asks about support in cmake
All build systems like build2, cmake and ninja have already added support for modules AFAIK. CMake am not sure that it supports all of it. Even otherwise all the build managers do require support from the underlying compiler
Danya🔥
Anyways, I think modules as a language feature won't be production ready for a long time
Anonymous
Anyways, I think modules as a language feature won't be production ready for a long time
Yeah i wasn't sure about cmake. I use build2 and it has awesome support. Looks like cmake is still in experimental stage but the reviews seem to be ok so far. Ninja supports modules on an experimental basis as well but it has been out for a while now. Modules are supported well by all major compilers as far as you are using modules that you define without templates code. The problematic issues are P1103R3 and P1815R2. The idea of prohibiting exposure of internal linkage constructs in template code is currently very difficult to implement in Clang and GCC because of the way they handle the augmented AST after the semantic analysis phase. This change requires considerable changes to how Clang and GCC handle the ASTs. This was a problem that was discovered later and so the compiler implementers could not voice their disagreement over this. This is where both GCC and Clang are stuck and it will be a considerable while before support for this is added. But this should not prevent people from mixing header files and modules in their code till this is resolved. Moreover most of the companies are still using only a C++17 (14) compiler. So the slow support for C++20 should not be an issue. This would be surely addressed before C++23 is ratified. Even otherwise, it would be another 1 or 2 years before organizations world wide would start moving to a C++20 toolset.
Danya🔥
I'd love to see modules as soon as possible
Danya🔥
But...
Anonymous
Is it too radical?
Danya🔥
No, it's not really necessary now C++17 is quite enough And for our codebase there are not many features that would increase developer's experience
Danya🔥
Ranges are great but they slow down build times
Anonymous
yeah
Danya🔥
No, it's not really necessary now C++17 is quite enough And for our codebase there are not many features that would increase developer's experience
Also, we have a requirement to be able to build with clang and libc++ (for Android builds) and well the support there is really bad for now
Anonymous
sleep,I've been tossing about arch today
Mohammad
Hi Can help me find (BURT2300) software ?