What are trade offs for “busy wait” vs “sleep”?

Going to sleep until the scheduler wakes you is the normal/prefered thing to do. Spinning (the alternative way to wait, without sleeping) is less usual and has the following effects: Keeps the CPU busy, and prevents other threads from using the CPU (until/unless the spinning thread finishes its timeslice and is prempted) Can stop spinning … Read more

What is the format of the x86_64 va_list structure?

The x86-64 System V ABi doc may help. It’s a reference, albeit lightweight. The Variable Argument List reference starts on page 54, then it goes on, page 56-57 documents va_list: The va_list Type The va_list type is an array containing a single element of one structure containing the necessary information to implement the va_arg macro. … Read more

Using M_PI with C89 standard

A conforming standard library file math.h is not only not required to, but actually must not define M_PI by default. In this context ‘by default’ means that M_PI must only get defined through compiler-specific tricks, most often undefined behavior through the use of reserved identifiers. Just define the constant yourself (you can use the name … Read more

How to undeclare (delete) a variable in C?

No, but you can create small minimum scopes to achieve this since all scope local variables are destroyed when the scope is exit. Something like this: void foo() { // some codes // … { // create an extra minimum scope where a is needed int a; } // a doesn’t exist here }

What exactly does fork return?

I’m not sure how the manual can be any clearer! fork() creates a new process, so you now have two identical processes. To distinguish between them, the return value of fork() differs. In the original process, you get the PID of the child process. In the child process, you get 0. So a canonical use … Read more

How to produce a NaN float in c?

Using floating point numbers, 0.0 / 0.0 isn’t a “divide by zero” error; it results in NaN. This C program prints -nan: #include <stdio.h> int main() { float x = 0.0 / 0.0; printf(“%f\n”, x); return 0; } In terms what NaN looks like to the computer, two “invalid” numbers are reserved for “signaling” and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)