Talula
hi guys, i am using non blocking i/o on a socket udp, but next i want to use again the blocking i/o, so how can i make it? which options should i use on setsockopt?
Are you using some kind of library/class for this? Because C/C++ doesn't support "non-blocking" natively.
Talula
i used setsockopt with the SO_RCVTIMEO option
Which Library? These are not native to C/C++, maybe I could recommend using another library that doesn't support non-blocking... And why in the world do you want to use blocking? If you want to block something from happening, do it manually... if you're using GUI, disable the controls on Window, if you're using server side, put it in a while loop while waiting for process to finish or if you're using it on CLI, do the same...
Alex
i am doing a server for download and upload of files during the download, i want a non blocking recvfrom, but after the download i want a blocking recvfrom
Ludovic 'Archivist'
musl rocks?
In terms of C standard library it is good, but also C is not always the best tool for every single task and suckless enthusiasts seem to think it is. LMDB and musl and some other minimalistic projects are very nice, but sometimes I would rather use C++ (which they call bloat without even considering that I do not use the hosted implementation)
Alex
hi guys, how can i divide a project in multiple files?
Talula
hi guys, how can i divide a project in multiple files?
By making libraries... depending what you're using to program, which language?
Alex
in C
Llll
Hello guys, does any one know why float, double, and long double have the same precision of 7 decimal places in MSVC?
Llll
I tried them all and each time after compilation, my value is truncated to only 7 decimal places in the console.
Llll
import <iostream>; import <numbers>; int main() { double pi = 0.12345678901234567890; std::cout << pi << std::endl; } After compilation, 0.1234567
줄리아 우지야노바
also you have f in end of your double literal, that makes it float literal
Llll
also you have f in end of your double literal, that makes it float literal
Yeah, I added that only for testing purpose. Forgot to take it off before posting. Sorry
Talula
in C
Distribute things in libraries, your main program is always small, put other function in different libraries.
Llll
Ha Ha. It's not right way to check precision
You see, I am studying from a book so I try to create possible error scenarios in my codes to see how everything works. Used this approach for testing value ranges for the integer types and it worked well. However, despite the sizeof function indicating that double has twice the bytes of float and as much byte as the long double, all three floating point data types happen to have a precision of 7 for the microsoft visual c++ 20 that I am using
Gani
/duolingo
Llll
use std::setprecision
std::setprecision works
Hussein
try to avoid libevent because it is bit of a legacy libev is a library for asychronous programming using a callback funcion so you are expected to do your networking with <sys/socket.h> but note that libev has slightly better performance than the others because it is more low level and close to the kernel libraries which are usually the fastest thing you can get out of your system
SO_RCVTIMEO doesn’t make your networking non-blocking it just sets a timeout for each packet (think of it as a portion of a message) so your server won’t wait forever if your a client went offline suddenly you should use (epoll on linux or kqueue on BSDs including MacOS) or use a cross platform library that works everywhere also read the messages above where I explain it to someone else before ☝️
Anonymous
in C
By using header files, Just search about it
Llll
I tried using the debugger but I didn't get anything useful. However, using the setprecision function, I saw that despite having each different floating point type value printed with a precision of 7 decimal places, it appears that it is the doing of microsoft. The setprecision with an argument of more than the maximum precision of any given floating-point type produces gibberish after the precision limit. So 7 decimal places is the standard for all floating-point data type in MSVC or so it seems.
Hussein
hi guys, how can i divide a project in multiple files?
it is a very good practice not to make your C files too long for readability and understandability assume that you have a function called int foo(){...} in a file called “foo.c” then you want to call from another file called “main.c” firstly the main should only exist in main.c (you can call this file whatever you want btw) you can create another file and call it “foo.h” when it would contain only the declaration of the function so instead of writing the whole function again in “foo.c” you would write only the following: int foo(); only with no main function in “foo.h” then in main.c before the main function you write: #include “foo.c” //with the double quotes or you can simple copy and paste: int foo(); into main.c before the main function then if you like to compile it you do: gcc foo.c main.c note that the order that you write main.c and foo.c doesn’t matter the compiler will always look for the main function then do its work
Jojo
Hey was wondering how to write c/c++ code to read and write from a doc or excel....or basically any sw with an input output tab any help?
줄리아 우지야노바
G
std::string getMessage() { char length[4]; fread(length, 4, sizeof(char), stdin); uint32_t len = *reinterpret_cast<uint32_t*>(length); char message[len]; fread(message, len, sizeof(char), stdin); std::string content(message, message + sizeof(message) / sizeof(message[0])); return content; }
G
could someone help me ajudar.com this function
G
the error is on that line
G
char message[len];
줄리아 우지야노바
char message[len];
VLA is gnu extension. You can directly read into std::string. Also you are violating strict aliasing rule when reinterpret casting char[] to uint32_t. You need to use std::bitcast or std::memcpy std::string getMessage() { char length[4]; fread(length, 4, sizeof(char), stdin); std::uint32_t len; std::memcpy(&len, length, 4); std::string content(len, '\0'); fread(message.data(), len, sizeof(char), stdin); return content; }
Anonymous
hi guys I don not know what went wrong with that lambda add function. can you help me with this bug?
Anonymous
#include<iostream> #include<string> using namespace std; class book{     public:         int price;         string name; }; int main(){     book a,b;     a.price=1;     b.price=1;     auto add=[](book& a,book& b)->decltype(a){         book c;         c.price=a.price+b.price;         return c;     };     book cc=add(a,b);     cout<<"cc price is"<<cc.price<<endl;     return 0; }
Hussein
boost asio
he wanted a C library boost is for C++
Jojo
libxls can parse xls and csv
So all sw have different libraries for this?🤔🤔
Silent
#include <iostream> using namespace std; int main() { long int t; cin>>t; while(t--) { int n,c=0,t=0; scanf("%d",&n); While(n>=0) { t=n%10; if(t==4) { c++; } n=n/10; } cout<<c<<endl; } return 0; } Why this code is taking input for more times than that t value
数学の恋人
You could have just used, book instead of that
数学の恋人
also if you insist on using decltype, that's not the way
数学の恋人
have a look at std::declval
Anonymous
I found the error. The compiler think the a in decltype(a) is a in (book& a,book& b),not the a I defined earlier in line one “book a,b” .
Anonymous
have a look at std::declval
The problem is not with decltype. And you shouldn't be using declval either here The problem can be fixed by either simply returning book or by using std::decay_t on the type returned from decltype
Anonymous
But if I define “book aa” in main and use decltype(aa) It tends to be no error
Anonymous
But if I define “book aa” in main and use decltype(aa) It tends to be no error
Because then decltype(aa) would be book and not book&.
Anonymous
Hello everyone I'm Sasikumar https://www.linkedin.com/in/duttaluru-sasikumar-9477ab188 Everyone let me connect in LinkedIn.
Anonymous
The problem here can be solved by simply omitting the return type
Omitting the return type will not work if he is compiling on a C++11 system and if there are multiple return statements.
Anonymous
С++11 is legacy
Lots of companies still use a C++11 or a C++14 compiler. The move to C++17 itself hasn't happened yet
줄리아 우지야노바
nothing stops from using c++17 or newer
줄리아 우지야노바
you can use c++17 and c++11 at once (i mean you don't have to rewrite the legacy code to C++17 to use C++17)
줄리아 우지야노바
I don't remember the new standards relaxing the existing restrictions.
줄리아 우지야노바
But I know many examples in which the new standards even make restrictions stricter
Anonymous
llvm uses C++14 Google uses C++14
No. Big companies don't migrate easily to the latest and the greatest. If you think they do, then you haven't worked in one. The problem is not that the compilers may have ABI compatability issues. The problem is that migration takes a long time and it has to be tested thoroughly. They can't take your word for it. At the end of the day it's a business and they would be happy to use an older version as long as it serves them. Google uses different versions for different teams. Fuschia OS team uses C++17 because when they started out many compilers already were offering C++17 support . The tensor flow team still uses C++11 as does the Nano team in GCP devops tools. C++11 is still being widely used as is C++14. C++17 is yet to see adoption at the same scale which would most likely happen soon as C++17 has had sufficient time to mature and be tested.
Anonymous
#include <stdio.h> unsigned int factorial( unsigned int n); int main () { int number = 5; int z =factorial( number ); printf("factorial of %d = %d \n",number,z); } unsigned int factorial( unsigned int n) { if(n==0) return 1; return n * factorial(n-1) ; }
#include <stdio.h> unsigned int factorial( unsigned int n); int main () { int number = 5; int z =factorial( number ); printf("factorial of %d = %d \n",number,z); } unsigned int factorial( unsigned int n) { if(n==0) return 1; return n * factorial(n-1) ; }
S
Which c++ smtp client you guys would prefer to send email? I am translating libcurl examples but it’s c
Ludovic 'Archivist'
Which c++ smtp client you guys would prefer to send email? I am translating libcurl examples but it’s c
Poco is a pretty common one by also pretty Java-ish as far as C++ is concerned
● Igor
in C++, is there any kind of mutex that works like in Rust? in Rust we can only access the data by locking the mutex, and its guaranteed to be unlocked at the end of the scope
METRO
guys
METRO
I have a problem, who can help me solve it?
Ercan
Hi, how to make write function show integers in C? Any idea?
Ercan
write function from the library unistd.h