ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
#include <iostream> #include <stdlib.h> using namespace std; int main() { char choice; cout << "Enter Choice: "; cin >> choice; choice = tolower(choice); while (choice != 'e' || choice != 'o'){ cout << "Invalid, Select Again!: "; cin >> choice; choice = tolower(choice); } return 0; }
chakiwinja
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
what do you think should do?
was thinking after the user input it should ask for a correct choice if the choice isn't 'e' or 'o'
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
put && instead of ||
okay let me try that
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
Anonymous
If we give input as 13/4 then output will be 4 ???write a C code
Llll
Hello, can anyone help me set up c++20 for gcc. I have version 12.1 on manjaro but even after enabling the flags -std=c++20 and -fmodules-ts, I still cannot compiled modules (i.e. import <iostream>;) for my code.
Llll
I get the message compiled module file is 'gcm.cache/./usr/include/c++/12.1.0/iostream.gcm'
Llll
Modules are still a work in progress, while they are implemented in the compiler, no build system makes use of them yet
How about clang? Having the version 13.0.1 installed but I am still unable to compile my code after enabling the -std=c++20 flag.
Anonymous
Hello, can anyone help me set up c++20 for gcc. I have version 12.1 on manjaro but even after enabling the flags -std=c++20 and -fmodules-ts, I still cannot compiled modules (i.e. import <iostream>;) for my code.
Module support for standard libraries is not a partof the C++20 standard. They are slated in for C++23. But Microsoft Visual Studio already supports this.
Anonymous
How about clang? Having the version 13.0.1 installed but I am still unable to compile my code after enabling the -std=c++20 flag.
Both Clang and gcc at present have only partial support for modules. And they are in particular only for modules you write
Llll
Module support for standard libraries is not a partof the C++20 standard. They are slated in for C++23. But Microsoft Visual Studio already supports this.
OK. Quite unfortunate because I just started learning c++ from the book beginning c++ and the author seems pretty sure that modules are available for most compilers. I was using visual studio but it is just resource intensive and time wasting so I thought that maybe manjaro being a rolling release distro should have the latest version of gcc which should have considerable support for c++20.
Llll
Do you know any other alternative compiler with c++modules support?
Llll
Beginning C++ by Ivor Horton????
Yes, beginning c++20 to be specific
Anonymous
Do you know any other alternative compiler with c++modules support?
Nopes. Except for Microsoft, no other compiler supports standard library imports
Anonymous
Yes, beginning c++20 to be specific
Ivor Horton is a horrible author (atleast his C++ books are) and his books are not standard compliant. He is known to encourage bad programming practices
Rumal
#include <stdio.h> int main() { for(printf("FLOWER");printf("YELLOW ");printf("FRUITS")) { break; } return 0; } The outuput of program is FLOWERYELLOW Can anyone explain this?I thought this will throw an error.
klimi
#include <stdio.h> int main() { for(printf("FLOWER");printf("YELLOW ");printf("FRUITS")) { break; } return 0; } The outuput of program is FLOWERYELLOW Can anyone explain this?I thought this will throw an error.
we run the inicialization code which outputs FLOWER; we run the condition code which outputs YELLOW and returns 0 which is false so we don't execute anything further in the loop
줄리아 우지야노바
for(A;B;C) { CODE; } equivalent to A; while(B) { CODE; C; }
klimi
return value doesn’t matter in this case
well yes, you would break the code, i was trying to be more explicit
ʙʀʜᴏᴏᴍ ⑇
How to show an Arabic word or a Japanese word in the OUTPUT
Anonymous
How to show an Arabic word or a Japanese word in the OUTPUT
do a research about returning utf-8 outputs.
ʙʀʜᴏᴏᴍ ⑇
I get it 👍🔥
ʙʀʜᴏᴏᴍ ⑇
do a research about returning utf-8 outputs.
And can I use the same thing in a another languages!? Right?!
Aquatica
And can I use the same thing in a another languages!? Right?!
Other languages usually support UTF-8 or 16 out of the box
Anonymous
And can I use the same thing in a another languages!? Right?!
Yes, it supports many languages such as: Russian, Arabic, Chinese, Japanese and other live languages
ʙʀʜᴏᴏᴍ ⑇
Thank you all ❤️
G
hi
G
how do i get the result of this function
G
SQLWCHAR* SqlClient::StringToSQLWCHAR(std::string _string) { std::string str = _string; std::wstring wstr = std::wstring(str.begin(), str.end()); SQLWCHAR* sqlwchar = (SQLWCHAR*)wstr.c_str(); return sqlwchar; }
Anton
Hi everyone! Me and my friend have two programs written in C language (let’s call them A and B) that are executing exactly same tasks. In particular: they do thread oriented job. But there’s one problem: program A is working significantly slower when compiled with -fsanitize=thread and crushes almost immediately, whilst B works as if nothing changed. Question: - Can someone suggest interface/utility that analyze performance (and can find potential bottlenecks) in a C program?
Magician
hey can anyone tell em why my cout statements dont print in a selection sort
Magician
it's so strange only one variable gets couted
'''''''
does the second approach take less time than the first? for (int i = 0; i < string1.length(); i++) // int j = string1.length(); for (int i = 0; i < j; i++) I mean to ask, is the string.length() cached during first iteration?
Anonymous
does the second approach take less time than the first? for (int i = 0; i < string1.length(); i++) // int j = string1.length(); for (int i = 0; i < j; i++) I mean to ask, is the string.length() cached during first iteration?
No it is not cached. But methods like size(), length() and end() are required by the standard to be very efficient and constant time. So practically there is no difference. You compute size or length in the loop everytime if the loop body does something that might change the size of the string. So which option you choose depends on your loop body. This is also precisely the reason why you should not change the container you are iterating on while using the range for loop. That is because the range for loop computes the end() iterator only once and any subsequent changes to the container may invalidate the end iterator and thus result in UB.
줄리아 우지야노바
const std::string& ss = "123fas"; while(i < ss.length()) { std::printf("%d", ss.at(i)); ++i; } in the compiled code, there is a check of the string size in each iteration, the string size is obtained each time from memory
줄리아 우지야노바
Maybe problem is that we still can change object in const methods using mutable fields?
Anonymous
>> You compute size or length in the loop everytime if the loop body does something that might change the size of the string. Compilers should cache the length in const context, but it doesnt happen
Because the standard recommends against this optimization. This shouldn't prevent an implementation from using it but generally they don't. It is also the reason why the standard places strict requirements on the efficiency of such methods. Also it is not just non const methods that the compiler has to worry about. Even calls to external methods need to be analysed. This places a much bigger burden on compilers for a relatively very small performance gain.
Anonymous
calls to external methods can be not analyzed, because u cant get nonconst ref from const ref(without UB, i mean)
For a non const ref used in the loop which calls an external method, the compiler can't cache size unless it knows everything that the external method does.
Anonymous
in this case it can cache, but it isnt
Read the post above my last one
Anonymous
in this case it can cache, but it isnt
Here is an example: std::string s {"hello"}; std::string const &r = s; void external(std::string& s, int& index); for( i = 0; i < r.size(); ++i){ //Do something external(s, i); }
줄리아 우지야노바
in my case, compiler knows, that const ref is temp object
줄리아 우지야노바
even if type of string will be const std::string(not reference), length size is not cached
Anonymous
in my case, compiler knows, that const ref is temp object
There are limits to what a compiler can and cannot do. Something that is very obvious to you may not be as simple for a compiler implementor. That is precisely why the standard explicitly calls this situation out and expects the implementations to instead focus on making these methods more efficient so that there is no performance impact when their results are not cached
Anonymous
I think compilers doesnt have good lifetime analysis nowadays. Maybe replacement of Clang AST in clang to high level intermediate language will solve this problem(in PoC there is special way to handle lifetimes)
Yes and it is not just a proposal. An implementation is also available. But there are limits to what it can do. Just plain lifetime analysis without a borrow checker can bring in only a few improvements. But C++ is not trying to emulate Rust. The lifetime analysis checks can at best handle some dangling references and pointers (using smart pointers alleviates this problem). They can't handle concurrency issues and more complicated scenarios. For example : The proposed lifetime analysis won't help with issues like in the code below: #include <iostream> #include <vector> int main() { std::vector<int> xs = { 10, 20, 30 }; auto it = xs.cbegin(); xs.push_back(40); std::cout << *it; // possible use-after-free: dereferencing an iterator that was invalidated }
줄리아 우지야노바
or analyzer will be very complicated and slow
Anonymous
줄리아 우지야노바
also high level IR optimizations can bring cool features, like this: std::vector<int> vec; for (auto i = 0u; i < 1024; i++) { vec.push_back(i); } could be changed to std::vector<int> vec{ 1, 2, 3, ... }; or at least std::vector<int> vec; vec.reserve(1024); for (auto i = 0u; i < 1024; i++) { vec.push_back(i); }
줄리아 우지야노바
But these are all dreams. Let's see what will happen in reality
줄리아 우지야노바
No it won't be of much help outside of a couple of cases.
btw the Rust compiler is still not fully disclosed: the Rust frontend has a lot of information about types, lifetime, and other little things that give a huge optimization potential. Therefore, my expectations about optimizing strings in C++, which the Rust compiler could do, remain in wet dreams(C++ is much more difficult to analyze than Rust)
줄리아 우지야노바
C++ is much more difficult to analyze than Rust, although it is still possible. But even rust can't cope with this, so we can assume that optimization of C++ at the maximum level is impossible at the moment
Anonymous
btw the Rust compiler is still not fully disclosed: the Rust frontend has a lot of information about types, lifetime, and other little things that give a huge optimization potential. Therefore, my expectations about optimizing strings in C++, which the Rust compiler could do, remain in wet dreams(C++ is much more difficult to analyze than Rust)
One again lifetimes and borrow checkings by themselves offer very limited optimization potential (like in the case where a compiler can infer that an object may not be changed in the loop). Knowing that you have shared references or a single mutable reference may help with such optimizations but those generally don't speed up your code by a large factor. Lifetime analysis and borrow checking are meant to be features to help with safer coding rather than optimization. These optimizations can be availed in C++ too by changing your code a bit but this might be viewed as premature optimization by many. Unless you carry out performance testing and see a marked improvement, there is no point in doing so.
Red Devil Shishir
how do i sort a structure in alphabetical order using pointers in C
the best for everyone
Red Devil Shishir
how do i sort a structure in alphabetical order using pointers in C
eg i have name of workers and need to sort them alphabaticaly by using pointer
Red Devil Shishir
i am just a beginner so dont know about lambda
Red Devil Shishir
i will check it out
Anonymous
i will check it out
You can customize the comparison function in c++.
Anonymous
How does one overcome problem of C skipping scanf second character request?
Anonymous
do a research about "c++ access database connector"