Why is there no strtoi in stdlib.h?

strtol() converts a string to an integer, a long integer but an integer nevertheless. There is atoi() but it should be avoided in most cases due to the fact that it lacks a mechanism for error reporting from invalid input.

Compiling without libc

If you compile your code with -nostdlib, you won’t be able to call any C library functions (of course), but you also don’t get the regular C bootstrap code. In particular, the real entry point of a program on Linux is not main(), but rather a function called _start(). The standard libraries normally provide a … Read more

Linking against an old version of libc to provide greater application coverage

Work out which symbols in your executable are creating the dependency on the undesired version of glibc. $ objdump -p myprog … Version References: required from libc.so.6: 0x09691972 0x00 05 GLIBC_2.3 0x09691a75 0x00 03 GLIBC_2.2.5 $ objdump -T myprog | fgrep GLIBC_2.3 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3 realpath Look within the depended-upon library to see … Read more

Why is libc++’s vector::const_reference not bool?

The motivation for this extension, which is detectable by a conforming program, and thus non-conforming, is to make vector<bool> behave more like vector<char> with respect to references (const and otherwise). Introduction Since 1998, vector<bool> has been derided as “not quite a container.” LWG 96, one of the very first LWG issues, launched the debate. Today, … Read more

Is snprintf() ALWAYS null terminating?

As the other answers establish: It should: snprintf … Writes the results to a character string buffer. (…) will be terminated with a null character, unless buf_size is zero. So all you have to take care is that you don’t pass an zero-size buffer to it, because (obviously) it cannot write a zero to “nowhere”. … Read more

Are types like uint32, int32, uint64, int64 defined in any stdlib header?

The C99 stdint.h defines these: int8_t int16_t int32_t uint8_t uint16_t uint32_t And, if the architecture supports them: int64_t uint64_t There are various other integer typedefs in stdint.h as well. If you’re stuck without a C99 environment then you should probably supply your own typedefs and use the C99 ones anyway. The uint32 and uint64 (i.e. … Read more

What’s the difference between hard and soft floating point numbers?

Hard floats use an on-chip floating point unit. Soft floats emulate one in software. The difference is speed. It’s strange to see both used on the same target architecture, since the chip either has an FPU or doesn’t. You can enable soft floating point in GCC with -msoft-float. You may want to recompile your libc … Read more

What are the mechanics of short string optimization in libc++?

The libc++ basic_string is designed to have a sizeof 3 words on all architectures, where sizeof(word) == sizeof(void*). You have correctly dissected the long/short flag, and the size field in the short form. what value would __min_cap, the capacity of short strings, take for different architectures? In the short form, there are 3 words to … Read more

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