What does the first “c” stand for in “calloc”?

According to an excerpt from the book Linux System Programming (by Robert Love), no official sources exist on the etymology of calloc. Some plausible candidates seem to be: Count or counted, because calloc takes a separate count argument. Clear, because it ensures that the returned memory chunk has been cleared. Brian Kernighan is reported to … Read more

Why isn’t there int128_t?

I’ll refer to the C standard; I think the C++ standard inherits the rules for <stdint.h> / <cstdint> from C. I know that gcc implements 128-bit signed and unsigned integers, with the names __int128 and unsigned __int128 (__int128 is an implementation-defined keyword) on some platforms. Even for an implementation that provides a standard 128-bit type, … Read more

Why is operator!= removed in C++20 for many standard library types?

In C++20 the way that the relational operators work was changed, notably with the introduction of the spaceship <=> operator. In particular, If you only provide operator==, then a != b is rewritten to !(a == b). From [over.match.oper]/3.4: The rewritten candidate set is determined as follows: For the relational ([expr.rel]) operators, the rewritten candidates … Read more

Why was std::pow(double, int) removed from C++11?

double pow(double, int); hasn’t been removed from the spec. It has simply been reworded. It now lives in [c.math]/p11. How it is computed is an implementation detail. The only C++03 signature that has changed is: float pow(float, int); This now returns double: double pow(float, int); And this change was done for C compatibility. Clarification: 26.8 … Read more

How to get IOStream to perform better?

Here is what I have gathered so far: Buffering: If by default the buffer is very small, increasing the buffer size can definitely improve the performance: it reduces the number of HDD hits it reduces the number of system calls Buffer can be set by accessing the underlying streambuf implementation. char Buffer[N]; std::ifstream file(“file.txt”); file.rdbuf()->pubsetbuf(Buffer, … Read more

Why wasn’t a specifier for `float` defined in `printf`?

Because in C variadic function calls, any float argument is promoted (i.e. converted) to a double, so printf is getting a double and would use va_arg(arglist, double) to get it inside its implementation. In the past (C89 and K&R C) every float argument was converted to a double. The current standard omits this promotion for … Read more

std::lexical_cast – is there such a thing?

Only partially. C++11 <string> has std::to_string for the built-in types: [n3290: 21.5/7]: string to_string(int val); string to_string(unsigned val); string to_string(long val); string to_string(unsigned long val); string to_string(long long val); string to_string(unsigned long long val); string to_string(float val); string to_string(double val); string to_string(long double val); Returns: Each function returns a string object holding the character representation … Read more

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