Why does glibc’s strlen need to be so complicated to run quickly?

You don’t need and you should never write code like that – especially if you’re not a C compiler / standard library vendor. It is code used to implement strlen with some very questionable speed hacks and assumptions (that are not tested with assertions or mentioned in the comments): unsigned long is either 4 or … Read more

“register” keyword in C?

It’s a hint to the compiler that the variable will be heavily used and that you recommend it be kept in a processor register if possible. Most modern compilers do that automatically, and are better at picking them than us humans.

Using GCC to produce readable assembly?

If you compile with debug symbols (add -g to your GCC command line, even if you’re also using -O31), you can use objdump -S to produce a more readable disassembly interleaved with C source. >objdump –help […] -S, –source Intermix source code with disassembly -l, –line-numbers Include line numbers and filenames in output objdump -drwC … Read more

What does the constant 0.0039215689 represent?

0.0039215689 is approximately equal to 1/255. Seeing that this is OpenGL, performance is probably important. So it’s probably safe to guess that this was done for performance reasons. Multiplying by the reciprocal is faster than repeatedly dividing by 255. Side Note: If you’re wondering why such a micro-optimization isn’t left to the compiler, it’s because … Read more

Why do you have to link the math library in C?

The functions in stdlib.h and stdio.h have implementations in libc.so (or libc.a for static linking), which is linked into your executable by default (as if -lc were specified). GCC can be instructed to avoid this automatic link with the -nostdlib or -nodefaultlibs options. The math functions in math.h have implementations in libm.so (or libm.a for … Read more

How to convert a string to integer in C?

There is strtol which is better IMO. Also I have taken a liking in strtonum, so use it if you have it (but remember it’s not portable): long long strtonum(const char *nptr, long long minval, long long maxval, const char **errstr); You might also be interested in strtoumax and strtoimax which are standard functions in … Read more

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