Chaser
Can I get easy understanding c++ pdf
Chaser
Any pdf available
Adriano
Hello, i have question. Which is one is effective ? type arr[x] = {0}; or type arr[x]; memset(arr, 0, sizeof(arr));
Just curious, what version of CPP is that? I just try to compile both and I can't.
Danya🔥
Dima
I thought zero was as an example
Dima
if its always zero then bruh
Danya🔥
Just never
Danya🔥
And if the type is not trivial, the second piece is not correct at all
Danya🔥
And if it is, it's just bad code
paper
Does android NDK use C++ directly or through java?
Pavel
Every part😁
It doesn't work like this, OOP is a huge topic that has articles, videos and even books about it all around internet. And instead of learning using these materials you want someone to repeat this information to you? :)
Anonymous
🥇
Anonymous
we will become 🥇
Ольга
Hello. I'm so sorry. I know that this group is for C and Cpp but maybe someone know Assembler NASM x86?
\Device\NUL
This code will never be a problem in terms of performance
Okay, silly me. it must be sizeof(arr) not sizeof(x).
Danya🔥
\Device\NUL
\Device\NUL
Hello. I'm so sorry. I know that this group is for C and Cpp but maybe someone know Assembler NASM x86?
Just ask your question. Don't ask to ask. If you ask for Assembly Programming group here it is https://t.me/assemblybr
پویا رحیم
hi. I'm gonna use opengl for vs code and i don't know what version of Glad should i download ? https://glad.dav1d.de/
Marcio
Somebody has the link to the so called OT group…?
Adriano
Hello, i have question. Which is one is effective ? type arr[x] = {0}; or type arr[x]; memset(arr, 0, sizeof(arr));
Ok, I made this into real C++ code and managed to compile. When you asked this quesiton the first thing that came to my mind is "the answer depends on what the compiler will do with this code". The answer for the GCC compiler is: 1) Without optimization the first option is more efficient as the second option will call a function, and more operations will have to be performed. 2) With full optimization "-O3", both options will produce *identical* binaries.
H
Why when scanning an integer you have to give the address?
touhou
Why when scanning an integer you have to give the address?
Because you want to store the data to the address of the specific variable. https://en.cppreference.com/w/cpp/io/c/fscanf
\Device\NUL
Why when scanning an integer you have to give the address?
Because you need to pass reference address of var if you want to change var value outside function
H
But you don't need an address to scan other data types, right?
\Device\NUL
But you don't need an address to scan other data types, right?
> you need to pass reference address of var if you want to change var value outside function
H
So the outside function is scanf here?
touhou
So the outside function is scanf here?
I suggest you to go through addresses, pointers, memory in c. You'll understand scanf() better after that.
H
Ok
Hanz
Can i define a macro by setting its value equal to a function? Something like: #ifndef INT_MIN #define INT_MIN std::numeric_limits<int>::min() #endif
The macro will be replaced literally as like you are calling that said function INT_MIN would not be fixed, but it's value would be std::numeric_limits<int>::min()
Anonymous
Ok, I made this into real C++ code and managed to compile. When you asked this quesiton the first thing that came to my mind is "the answer depends on what the compiler will do with this code". The answer for the GCC compiler is: 1) Without optimization the first option is more efficient as the second option will call a function, and more operations will have to be performed. 2) With full optimization "-O3", both options will produce *identical* binaries.
Danya already provided the answer to this question. As far as your reply is concerned, the first case is not correct. How do you think the compiler initializes memory? Both the options will be equally good as far as speed is concerned and the second option will not work for non trivial types (non POD types) as already pointed out
Adriano
Danya already provided the answer to this question. As far as your reply is concerned, the first case is not correct. How do you think the compiler initializes memory? Both the options will be equally good as far as speed is concerned and the second option will not work for non trivial types (non POD types) as already pointed out
That's the thing, I don't need to "think" how the compiler initializes the memory. I can just ask, and I will know for a fact. In order to compile the code, I supposed the type was a char[16]. In this case, GCC will do exactly the same thing for any of the following pieces of code: 1) char x[16] = {0}; 2) char x[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 3) char x[16]; memset(x, 0, sizeof(char[16])); And this is how GCC tells me it will do: xorl %eax, %eax The funny thing is why does it write that assembly instead of this: mov eax,0x0 Apparently, the xor code is faster than the mov one, and that's what GCC will do when you use the -O3 switch.
Adriano
Which is exactly what happens in both the cases the OP suggested. So your saying that calling memset will be slower without the optimization flag is not correct.
Without the optimization flag there will be a function call for memset. That is extra operations and those aren't free. Without optimization the memset option will necessarily be less efficient.
Anonymous
Without the optimization flag there will be a function call for memset. That is extra operations and those aren't free. Without optimization the memset option will necessarily be less efficient.
I just tried compiling the code with -O1 , -O2 and -O3 on both Clang and gcc. The compiler is smart enough to allocate storage for the array in a register in all the 3 cases.
Adriano
I just tried compiling the code with -O1 , -O2 and -O3 on both Clang and gcc. The compiler is smart enough to allocate storage for the array in a register in all the 3 cases.
I'm not saying that the compiler is not smart. I am just saying that GCC without optimization (-O1 is optimization) will write code that represents more operations, namely the call for the function memset, than in the other situations. And again, I'm not supposing anything. I'm talking about the actual assembly output. Here is my command line: g++ main.cpp -S You can try it yourself, and then diff the files and you'll see that the difference is the function call.
Anonymous
I'm not saying that the compiler is not smart. I am just saying that GCC without optimization (-O1 is optimization) will write code that represents more operations, namely the call for the function memset, than in the other situations. And again, I'm not supposing anything. I'm talking about the actual assembly output. Here is my command line: g++ main.cpp -S You can try it yourself, and then diff the files and you'll see that the difference is the function call.
I just did. In the example case that you suggested i.e char [16], the compiler easily figured out that it can be stored in an array. For a larger array which can't fit into a register (for example I did a atomic RMW operation to force memory allocation), the compiler has the same behavior for both braced initialization and memset. This is because the compiler inserts a call to memset for the braced initialization case anyway. So the performance is the same
Anonymous
I am trying it on my laptop and sending these messages via phone. I will sign in to telegram web and send it across
ㅤㅤㅤ
How to take unknown number of input from user. If we want to get input in array or vector we ask "n" to create n size array. How to get input without n
Pavel
How to take unknown number of input from user. If we want to get input in array or vector we ask "n" to create n size array. How to get input without n
You can use vector and while loop, in the loop read and add to vector until encounter some predefined special case (empty input) to stop reading entries
ㅤㅤㅤ
Please provide any code or example for predefined special case
Adriano
No, not like that. It works only in pairs. You can wrap those other objects into a struct, a union, a vector or whatever is best for you, and then add that into your map.
Klaus
During which phase templates are processed ?
Klaus
Preprocessing, compilation, linking execution?
paper
During which phase templates are processed ?
At compile-time ( but it depends on the implementation )
Danya🔥
At compile-time ( but it depends on the implementation )
How does processing templates depend on a processor architecture?
Kiss my Toes
Anybody, how does opening a new tab works technically
Danya🔥
Anybody, how does opening a new tab works technically
You can read chromium source code and figure out it yourself
Kiss my Toes
You can read chromium source code and figure out it yourself
yes i have chromium already, i should have framed the question to point to frontend, generally what am asking for is how this works on the frontend e.g if you are to use chromium as the engine and you are building your own frontend
Kiss my Toes
i just need a little direction, maybe a doc or something
Kiss my Toes
What do you mean by frontend? A web app?
Yes cause definitely i will have a frontend that communicates with the engine
Kiss my Toes
For-example as a frontend dev e.g for chrome, what kind of steps you would take to open a new tab
Danya🔥
And why do you ask it here? In C++ chat?
Kiss my Toes
Kiss my Toes
Have you even tried googling?
yes, no resources so far
Kush
anyone doing codechef??
Ольга
Good day. Maybe someone knows. How it is possible to implement such addition in an array[1,2,3,4]like first 0 seconds 1... 3-t is 1+2..... Output [0,1, 3,6] . I will be grateful
Ольга
Like 0 1 1+2 1+2+3 Output[0,1,3,6]
I make something like this for(i=0;i<m-1;i++){ suma+=a[i]; printf("%d", suma) } it's works but I don't now that is right. Because numerat the elements not correct ant first element is 1 but not 0
Leovan
Whos know how to declare variable with user class type (like extern)? I need to create global class, but I can define it in func() only (because of variable which i can get only in this function): extern MyClass class; void func(int variable) { class MyClass(variable); } void another_func() { // use class }
\Device\NUL
That's why compiler prefer xor to zeroing rather than mov
\Device\NUL
i think the efficient way is type arr[x] = {0}; since it does same thing with memset(arr, 0, sizeof(arr)); and it doesn't call memset func
Danya🔥
Pre-mature optimizations again.. Aren't you tired of it?
\Device\NUL
Pre-mature optimizations again.. Aren't you tired of it?
yeah I know, Idk why the heck I'm paranoid of performance
Danya🔥
yeah I know, Idk why the heck I'm paranoid of performance
If you're paranoid about performance, you shouldn't pre-mature optimize :)
\Device\NUL
But just giving compiler the job for optimization is clearly stupid even with -O3 . since different compiler doesn't guarantee give same output with another compiler.
Adriano
But just giving compiler the job for optimization is clearly stupid even with -O3 . since different compiler doesn't guarantee give same output with another compiler.
Sooner or later you'll have to rely on the compiler. There's no other way your code will run. You might think: if I follow the specification, then I can guarantee that my code will be efficient in any compiler. No, you can't. It's not guaranteed that every compiler will do exactly what was intended when they wrote the specification. I never forget the day I read about std::valarray in the "C++ The Programming" language and went on to rewrite some code with matrix operations that I needed to efficient only to find out that every compiler at the time just ignored the intent behind std::,valarray, to the point that even following strictly Stroustrup recommendation, my program run slower than using normal std::vectors.