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. 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 constants (e.g. ‘xy’) are valid, although rarely useful … Read more

Get int value from enum in C#

Just cast the enum, e.g. The above will work for the vast majority of enums you see in the wild, as the default underlying type for an enum is int. However, as cecilphillip points out, enums can have different underlying types. If an enum is declared as a uint, long, or ulong, it should be … Read more

Downcasting in Java

Downcasting is allowed when there is a possibility that it succeeds at run time: In some cases this will not succeed: When a cast (such as this last one) fails at runtime a ClassCastException will be thrown. In other cases it will work: Note that some casts will be disallowed at compile time, because they … Read more

How do I check if a string is a number (float)?

Which, not only is ugly and slow I’d dispute both. A regex or other string parsing method would be uglier and slower. I’m not sure that anything much could be faster than the above. It calls the function and returns. Try/Catch doesn’t introduce much overhead because the most common exception is caught without an extensive … Read more