Natanim
Database connectivity with c++ SQL pdf
🇸🇩
did someone free?
🇸🇩
i need help about c++
Anonymous
did someone free?
Did »» *Is What kind of help?
Arry
\
Aref
hi, Is it possible to create a recursive function as a lambda?
Aref
in c++
Chri~
Hii, someone can help me with an easy problem in c++?
Chri~
#include <iostream> using namespace std; double add(double a, double b){ return a + b; } double sott(double a, double b){ return a - b; } double molt(double a, double b){ return a * b; } double divi(double a, double b){ return a / b; } int main(){ int Opr=0; double numero1; double numero2; double res; cout << " Addizione = 1\n Sottrazione = 2\n Moltiplicazione = 3\n Divisione = 4\n Che operazione vuoi eseguire?\n "; cin >> Opr; cout << "\n Qual'è il primo numero?\n"; cin >> numero1; cout << "\n Qual'è il secondo numero?\n"; cin >> numero2; res=(numero1, numero2); cout << "il risultato è " << res; } how can I set the operations whitout the switch? sry if the code is in italian
Chri~
res=add(numero1, numero2); for the add, but how can i set that the user can decide the operation?
Chri~
(I hope I explained myself)
Chri~
so there'arent any solutions without using the if, else and switch?
\Device\NUL
But it's not really a got idea, you will screwed up with nested of nested of nested ternary
Chri~
oh ok tysm, i'll try w the if and else
Chri~
double add(double a, double b){ return a + b; } double sott(double a, double b){ return a - b; } double molt(double a, double b){ return a * b; } double divi(double a, double b){ return a / b; } int main(){ int Opr=0; double numero1; double numero2; double res = 0; cout << " Addizione = 1\n Sottrazione = 2\n Moltiplicazione = 3\n Divisione = 4\n Che operazione vuoi eseguire?\n "; cin >> Opr; cout << "\n Qual'è il primo numero?\n"; cin >> numero1; cout << "\n Qual'è il secondo numero?\n"; cin >> numero2; if (Opr=1){ res=add(numero1, numero2); cout << "il risultato è " << res; }else {return 0;} if (Opr=2){ res=sott(numero1, numero2); cout << "il risultato è " << res; }else {return 0;} if (Opr=3){ res=molt(numero1, numero2); cout << "il risultato è " << res; }else {return 0;} if (Opr=4){ res=divi(numero1, numero2); cout << "il risultato è " << res; }else {return 0;} if (Opr>4){ cout << "impossibile! "; }else {return 0;} why in this way the compilator print all the operation?
Hussein
now you run your program with gcc and it runs twice as fast in benchmarks compared to MSVC
pavel
how so?
Different os
Hussein
Different os
oh.. it was trying to compute finbonacci sequence it is just computation on the same architecture nothing requires system calls also both on windows using mingw and MSVC
Sunil
anyone help me with a c# code i m new to coding ....
Hussein
Anonymous
C# is very different than C or C++
Yes, C/C++ can't C# because they got no glasses
CoolkingX
Guys where to study data structure and algorithm with c++
void
CoolkingX
Site plz
Sir
Do you want course or book?
CoolkingX
I'm a collage student so can't afford either
CoolkingX
Free sites
CoolkingX
Pardon?
void
Guarantee what?
from man pages The malloc() and calloc() functions return a pointer to the allocated memory, which is suitably aligned for any built-in type. On error, these functions re- turn NULL. NULL may also be returned by a successful call to malloc() with a size of zero, or by a successful call to calloc() with nmemb or size equal to zero.
void
Guarantee what?
NOTES By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. In case it turns out that the system is out of memory, one or more processes will be killed by the OOM killer. For more information, see the description of /proc/sys/vm/overcommit_memory and /proc/sys/vm/oom_adj in proc(5), and the Linux kernel source file Documentation/vm/overcommit-account- ing.rst.
void
for pet proyects went nice, for production ones, is just a joke
pavel
for pet proyects went nice, for production ones, is just a joke
It's bound case. Honestly any system allocator just a joke for production
void
touche
Sandeep
Hey if anyone knows any project in c++ that we can do in one month and good for resume plz share
Anonymous
Avi jais
Write a program to calculate the sun of all numbers which are divisible by 3 and contains two digit only.... Eg...Divisible by 3 ....3,66,9,45 Contains two digit ....66,88,45,34 Sumof all numbers.....3+66+9+45+3+66+9+45=Result 246..... Can anyone solve thid
Hussein
NOTES By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. In case it turns out that the system is out of memory, one or more processes will be killed by the OOM killer. For more information, see the description of /proc/sys/vm/overcommit_memory and /proc/sys/vm/oom_adj in proc(5), and the Linux kernel source file Documentation/vm/overcommit-account- ing.rst.
malloc is implemented by glibc not by the kernel malloc() calls sbrk() if the memory allocated is smaller than the provided memory page while mmap() is called if the memory allocated is larger sbrk() returns 0 on sucess and -1 on error mmap() returns an address to the mapped area and on failure it returns ( (void *) -1 ) both are handled correctly in case of an error and malloc will return
Avi jais
Write a program to calculate the sun of all numbers which are divisible by 3 and contains two digit only.... Eg...Divisible by 3 ....3,66,9,45 Contains two digit ....66,88,45,34 Sumof all numbers.....3+66+9+45+3+66+9+45=Result 246..... Can anyone solve thid
Hussein
NOTES By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. In case it turns out that the system is out of memory, one or more processes will be killed by the OOM killer. For more information, see the description of /proc/sys/vm/overcommit_memory and /proc/sys/vm/oom_adj in proc(5), and the Linux kernel source file Documentation/vm/overcommit-account- ing.rst.
Also I read the exact article online it is misleading the person who wrote it didn’t clearly understand the bugs section when he read it “”” On Linux, there are no guarantees like those suggested above under MAP_NORESERVE. By default, any process can be killed at any moment when the system runs out of memory. “””
Hussein
it says that if the process was killed mmap() will fail which is the function used by malloc
it didn’t say that it will fail without returning an error also all other bugs was fixed in version 2 of the kernel
Hussein
I talking about this line: By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available.
“”” By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. In case it turns out that the system is out “””
void
still only if the system runs out of memory
Yes, but this makes irrelevant to check if malloc return an address or not
Hussein
Yes, but this makes irrelevant to check if malloc return an address or not
this explains the situation were your program will be killed rather than given memory which clearly not only cause malloc to fail, your entire program will be killed anyway if you are receiving a kill signal not allocating enough memory will be the least of your concerns also this is unavoidable even on windows
Hussein
math would help but no it isn’t necessary
pavel
I do embedded realtime software mostly, malloc memory only once on start. If you fail - you will know it on a beginning
pavel
System allocator is slow, at least you should use pmr allocator if you try to avoid such problems
void
Yes, but really nobody check malloc pointers
Thanks, I working on C89 for non stop fault tolerant systems. On this systems Guardian malloc's returned value don't follow the current GNU's behaviour. Is there any implementation of CPP polymorphic allocator for C89?
pavel
But i don't think it mature
void
thanks
pavel
Thanks, I working on C89 for non stop fault tolerant systems. On this systems Guardian malloc's returned value don't follow the current GNU's behaviour. Is there any implementation of CPP polymorphic allocator for C89?
You can check o1heap on github Desc in readme O1heap is a highly deterministic constant-complexity memory allocator designed for hard real-time high-integrity embedded systems. The name stands for O(1) heap.
Hussein
Thanks, I working on C89 for non stop fault tolerant systems. On this systems Guardian malloc's returned value don't follow the current GNU's behaviour. Is there any implementation of CPP polymorphic allocator for C89?
look this isn’t about malloc the same bug is mentioned in mmap() because malloc utilises it which is created by kernel devs not the gnu project and the bug you are talking about only applies if your process it hog most of the RAM on the entire computer which will be killed when you run it on all operating systems not just linux and will cause undefined behavior because it doesn’t matter anymore since you are getting killed anyway even before your programs crash or reads a buffer that hasn’t been allcoated
Hussein
look this isn’t about malloc the same bug is mentioned in mmap() because malloc utilises it which is created by kernel devs not the gnu project and the bug you are talking about only applies if your process it hog most of the RAM on the entire computer which will be killed when you run it on all operating systems not just linux and will cause undefined behavior because it doesn’t matter anymore since you are getting killed anyway even before your programs crash or reads a buffer that hasn’t been allcoated
Hussein
Thanks, I working on C89 for non stop fault tolerant systems. On this systems Guardian malloc's returned value don't follow the current GNU's behaviour. Is there any implementation of CPP polymorphic allocator for C89?
look this isn’t about malloc the same bug is mentioned in mmap() because malloc utilises it which is created by kernel devs not the gnu project and the bug you are talking about only applies if your process it hog most of the RAM on the entire computer which will be killed when you run it on all operating systems not just linux and will cause undefined behavior because it doesn’t matter anymore since you are getting killed anyway even before your programs crash or reads a buffer that hasn’t been allcoated
void
but this, makes check malloc's return irrelevant
void
https://github.com/pavel-kirienko/o1heap this looks kinda nice
Hussein
but this, makes check malloc's return irrelevant
to kill process a kill signal has to travel for few miliseconds and since basically the os gave up on your process mmap will return an invalid address for malloc that will point to a non-existant memory page that hasn’t been created yet for your program (because there isn’t enough RAM and space in the swap partition on the disk) so you might get a segfault if the kill signal arrived too late and your program read that invalid address or just your program will get killed first but your program will crash anyway so a segfault and kill signal or only a kill signal doesn’t matter since your program will fail anyway