Multi-character constant warnings

According to the standard (§6.4.4.4/10) The value of an integer character constant containing more than one character (e.g., ‘ab’), […] is implementation-defined. long x = ‘\xde\xad\xbe\xef’; // yes, single quotes This is valid ISO 9899:2011 C. It compiles without warning under gcc with -Wall, and a “multi-character character constant” warning with -pedantic. From Wikipedia: Multi-character … Read more

how portable is end iterator decrement?

I think this is the relevant clause: ISO/IEC 14882:2003 C++ Standard 23.1.1/12 – Sequences Table 68 lists sequence operations that are provided for some types of sequential containers but not others. An implementation shall provide these operations for all container types shown in the “container” column, and shall implement them so as to take amortized … Read more

Proper shebang for Python script

#!/usr/bin/env python is more portable because in general the program /usr/bin/env can be used to “activate” the desired command without full path. Otherwise, you would have to specify the full path of the Python interpreter, which can vary. So no matter if the Python interpreter was in /usr/bin/python or in /usr/local/bin/python or in your home … Read more

Is there any “standard” htonl-like function for 64 bits integers in C++?

#define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32)) #define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32)) The test (1==htonl(1)) simply determines (at runtime sadly) if the hardware architecture requires byte swapping. There aren’t any portable ways to determine at compile-time what … Read more

Is char *envp[] as a third argument to main() portable

The function getenv is the only one specified by the C standard. The function putenv, and the extern environ are POSIX-specific. EDIT The main parameter envp is not specified by POSIX but is widely supported. An alternative method of accessing the environment list is to declare a third argument to the main() function: int main(int … Read more

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