Date: Wed, 4 Jul 2018 07:30:54 -0500 From: Antonio Olivares <olivares14031@gmail.com> To: Shane Ambler <FreeBSD@shaneware.biz> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: Clang++ stdlib/cstdlib.h workaround Message-ID: <CAJ5UdcM7yhBUdPu7fgDazZmXCU3RKVBDz3TkW8s9SgLAPY9SOA@mail.gmail.com> In-Reply-To: <f907f846-f607-40a1-c925-c04d1569ac47@ShaneWare.Biz> References: <CAJ5UdcP-Hpa%2BYqAkwkrv4ec_mV=CaTzDo%2BkCAADd-JKb25OdeQ@mail.gmail.com> <f907f846-f607-40a1-c925-c04d1569ac47@ShaneWare.Biz>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday, July 3, 2018, Shane Ambler <FreeBSD@shaneware.biz> wrote: > On 04/07/2018 04:08, Antonio Olivares wrote: >> Dear kind folks, >> >> I have a cpp file that used stdlib.h and it compiled and ran successfully. >> I am trying it out with clang and it returns errors that it cannot find >> stdlib.h, I remove the stdlib.h include statement and it still complains. > > You can add -I<path> as an argument that tells clang where to search for > header files. -L<path> does the same for libraries. Even when you remove > it another included file may still want it. > > clang++ -I/usr/include -L/usr/lib -o myapp myfile.cpp > >> I made a copy of the c++ file and it compiles and runs correctly, but I >> removed some stuff " --- " and only output the numbers. How do I deal with >> stdlib.h requirements? >> >> The program finds numbers that are triangular and square. It fails for >> numbers that are bigger than 2147483647. > > Does that number have any significance to you? It is the largest number > that can be held by a 32bit signed integer. You can use an unsigned int > to get twice that or you can use a long long to get a 64bit integer. > > Also related is that the math library functions have several variations > that take different size arguments. > > -- > FreeBSD - the place to B...Software Developing > > Shane Ambler > > Shane, Thanks for your input. For the moment I have removed the header file #include <stdlib.c> >From the c++ program. In a for loop part, I had a set of statements to output the values where the number was a triangular and square at the same time in two lines. This was where the program was failing to compile and I was concluding incorrectly that it had to do with the stdlib.h or cstdlib.h file. #include <iostream> #include <math.h> using namespace std; int main() { int i; int n; int k; cout << "This program searches for numbers that\n"; cout << "are both square and triangular\n"; cout << "Up to what number do you want to search?\n\n"; cout << "Enter number: "; cin >> n; for (i=1; i<n; i++) { k = (i*(i+1))/2; if (sqrt(k) - int(sqrt(k)) == 0) cout << "\n" << k << " is a triangular number when i = " << i << "." << endl; } cout << "\n\n"; return 0; } About the big number, it would be nice to get it working for bigger numbers, but I would need to run it on amd64 freebsd machine at work. Maybe at some other time we can revisit this issue. Thank you for your assistance. When running the program if I enter a number like 10,000,000 I get bad output. If I stop at 1,000,000 I get correct output. https://oeis.org/search?q=0%2C1%2C36%2C1225%2C41616%2C&language=english&go=Search Best Regards, Antonio
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ5UdcM7yhBUdPu7fgDazZmXCU3RKVBDz3TkW8s9SgLAPY9SOA>