Avoid Overflow when Calculating π by Evaluating a Series Using 16-bit Arithmetic?

Take a look at related QA: Baking-Pi Challenge – Understanding & Improving Its using Wiki: Bailey–Borwein–Plouffe_formula which is more suited for integer arithmetics. The real challenge however would be: How do I convert a very long binary number to decimal?. As you probably want to print the number in dec base … Also if you … Read more

How C strings are allocated in memory?

When you write const char *ptr = “blah blah”; then the following happens: the compiler generates a constant string (of type char []) with the contents “blah blah” and stores it somewhere in the data segment of the executable (it basically has a similar storage duration to that of variables declared using the static keyword). … Read more

Infinite recursion in C

Whenever you call a function, the arguments are pushed on the stack, which means that data on the stack segment is “allocated”. When the function is called, the return adress is also pushed on the stack, by the CPU, so it knows where to return to. In your example case this means, that no arguments … Read more

how to set close-on-exec by default

No and no. You simply need to be careful and set close-on-exec on all file descriptors you care about. Setting it is easy, though: #include <fcntl.h> fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); #include <unistd.h> /* please don’t do this */ for (i = getdtablesize(); i –> 3;) { if ((flags = fcntl(i, F_GETFD)) != -1) … Read more