𝙰.𝚁.𝚂 (𝙳𝙽𝙳)
#include <iostream> using namespace std; int main() { bool test; cout << test << endl; return 0; } I cannot stop at bool test; No matter how many optimizations I disable... it seems as if it gets removed or something.
𝙰.𝚁.𝚂 (𝙳𝙽𝙳)
#include <iostream> using namespace std; int main() { bool test; cout << test << endl; return 0; } I cannot stop at bool test; No matter how many optimizations I disable... it seems as if it gets removed or something.
#include <iostream> using namespace std; int main() { bool test; do { test = true; } while(test); return 0; } Also, I've tested here where the variable gets used. But inside another scope... So... when does the variable get created??
Pavel
#include <iostream> using namespace std; int main() { bool test; do { test = true; } while(test); return 0; } Also, I've tested here where the variable gets used. But inside another scope... So... when does the variable get created??
So, there are multiple answers for that. By the standard it's created in the outer scope and destroyed at the end of that scope. But the compiler can do optimizations to your code while these optimizations don't change observable behavior of the app (this doesn't count any UB, so be careful with that). So in fact the value may not exist at all. Also infinity loop without an exit condition is UB, so there are no guarantees about that, so the compiler is free to generate anything from this code or even not generate anything for it at all
Pavel
Don't mind the infinity loop. It's just an example I made up for testing. So the compiler creates the variable just right before the it gets it's value? Inside the scope?
It depends, it can be that it becomes the part of the code instruction and memory for it is not allocated on the stack at all. You can use godbolt.org to investigate the assembly generated for your code for debug and release versions
Pavel
Variables also can be stored and passed through processor registers
Pavel
I wish I knew assembly. Compilers are really confusing... XD
If you just want to debug your code, you need to disable optimizations (depends how you compile it, sometimes it's as easy as set "debug" instead of "release" in your IDE)
𝑪𝒐𝒃𝒓𝒂
How did you guys leaned to code
𝙰.𝚁.𝚂 (𝙳𝙽𝙳)
If you just want to debug your code, you need to disable optimizations (depends how you compile it, sometimes it's as easy as set "debug" instead of "release" in your IDE)
Thanks. I'm using makefiles and set the optimization flag to -O0. I somehow understood it better with a few experimentation. I guess gdb cannot detect that line of code because the compiler optimized it. Thus being unable to set breakpoint there.
𝙰.𝚁.𝚂 (𝙳𝙽𝙳)
I was really confused because I thought it was supposed to stop there. I guess that's not always true. But what's interesting is that the optimizations are not done to strings (I suppose). I can declare a string variable and not initialize it. And gdb can stop there.
Roxifλsz 🇱🇹
@roxifas this is an ad right
Idk, looks like just some C++ presentation vid, channel looks legit at first glance too
𝙰.𝚁.𝚂 (𝙳𝙽𝙳)
𝙰.𝚁.𝚂 (𝙳𝙽𝙳)
Natanim
I was trying to accept names in cpp and save it to a file in binary and then display it . But everytime the display comes the first letters of each names are cut off, can anyone help me with this. I wanted to forward the code but its too long here
momo
Could i know that is it good to learn major in artificial intelligence during degree in university?
Dima
separate being in your university and practice
momo
separate being in your university and practice
Hrmmm so actlly what university teach us is not that much important?
Anonymous
Anyone? it's kind of urgent please
try setting your buffer to all nulls, before you write your name
momo
I am thinking that which major in computer science is the most suitable for me
Anonymous
otherwise you most likely have an issue with your pointer
Natanim
try setting your buffer to all nulls, before you write your name
What do you mean? It is a program to accept names for a booking hotel
Anonymous
yes.. when you go to memcpy(buf, name, size); or strcpy(buf, name, size); for (int i = 0; i < SIZEOFBUF; i++) buf[i] = 0; THEN copy your name to it
Natanim
system("cls"); int r,flag; ofstream fout("Record.txt",ios::app); cout<<"\n Enter Customer Details"; cout<<"\n **********************"; cout<<"\n\n Room no: "; cin>>r; flag=check(r); if(flag) cout<<"\n Sorry..!!!Room is already booked"; else { room_no=r; cout<<" Name: "; gets(name); cin.ignore(); cout<<" Address: "; gets(address); cin.ignore(); cout<<" Phone No: "; gets(phone); cin.ignore(); fout<<room_no<<"\t"<<name<<"\t"<<address<<"\t"<<phone<<endl; cout<<"\n Room is booked!!!"; } cout<<"\n Press any key to continue!!"; getch(); fout.close();
Anonymous
where is name defined
Natanim
where is name defined
In a class named "Hotel"
Anonymous
i cant help you without seeing how its defined
Natanim
i cant help you without seeing how its defined
The code is too long to send, may i pm you?
Жанарыс
How can I write sin^7x^6
Pavel
-D is an optimization flag? Or preprocessor flag? I can't understand.
Wait, I've read the docs incorrectly, nevermind this, and I've read description of -O0 wrongly as well
𝙰.𝚁.𝚂 (𝙳𝙽𝙳)
Seems like this is the least optimization we can have...
adnanhossainme
#include <iostream> const int nmax = 100001; bool isPrime[nmax]; int listPrime(int num){ for(int i = 2; i<=num;i++){ isPrime[i] = true; } for(int i = 2; i<=num/2;i++){ if(isPrime[i]==true){ for(int j =i*2;j<=num;j+=i){ isPrime[j] = false; } } } for(int i=2;i<=20;i++){ if(isPrime[i] == true){ return i; } } } int main (){ //Qn: Call the above function and get return all prime number lists from 1-100 // but dont touch listPrime Function untill you think you can not do it return 0; }
okkk
vmro how to start coding?
okkk
i just gave my jee exam
okkk
from where?
okkk
i am noob🥲
okkk
is it enough
okkk
coz in any field the base building is the most important thing
okkk
ohkk
okkk
any suggestions?
okkk
in 2 months clg will start so basics will be enough right?
okkk
i dont know what to search buddy🥲
²
why not C Primer Plus by Stephen Prata?
Anonymous
why not C Primer Plus by Stephen Prata?
Not a standard compliant book and riddled with errors in the earlier editions. Not a recommended book
okkk
#res
what to read there... lot of messages there
Anonymous
what to read there... lot of messages there
Read the first two messages there
okkk
Read the first two messages there
which book would u suggest for learning c++
Anonymous
which book would u suggest for learning c++
Did you read the messages that I suggested earlier?
Anonymous
yes
So did you not find the recommended books there?
okkk
there are options thats why im asking
Anonymous
there are options thats why im asking
For Beginners, you can choose either one of the two books mentioned. Both are good. For intermediate and advanced, read all the books in the order specified
okkk
and any lecture source.. u can suggest?
adnanhossainme
and any lecture source.. u can suggest?
Just search on yt. If you cant do that then just leave
Anonymous
and any lecture source.. u can suggest?
No. The suggested books are the best option for learning if you want your basics to be strong
²
step first learn c++ step second 999999$/sec
𝟶𝚡𝟻𝟿
Hello, please what are the softwares I'll need if I want to start practicing c/c++ What will I use to run it and how do I set it up?
𝟶𝚡𝟻𝟿
What OS do you use?
Windows 10 Pro
Pavel
Windows 10 Pro
You can download Visual Studio Community Edition (not Visual Studio Code, that's a different thing), find some tutorials how to use it, and set it up with C++ components. This should be enough to start. Tutorials are important because it's not user-friendly at the beginning, difficult to find where is what.
SR27
I am reading Operating system and have ONE Question in my mind IS os is always in the main memory ?
Chika
I'm using a getline function in my program when execution reaches it, it doesn't waot gor user input it just continues.
Chika
Please what is the problem?
Michel
I'm running through some CUDA examples: sumCommMultiBlock<<<1, blockSize>>>(dev_out, gridSize, dev_out); cudaDeviceSynchronize(); cudaMemcpy(&out, dev_out, sizeof(int), cudaMemcpyDeviceToHost); Is cudaDeviceSynchronize() actually needed there? Doesn't the flow of the program wait for all the threads of the kernel to be finished?
Chika
string storeContact(){ String contactName; cout << " Enter contact name "; getline (cin, contactName); cout << contactName << endl; return contactName; }