Cakephp-3.x: How to change the data type of a selected alias?

As of CakePHP 3.2 you can use Query::selectTypeMap() to add further types, which are only going to be used for casting the selected fields when data is being retrieved. $query = $table ->find() ->select([‘alias’ => ‘actual_field’, /* … */]); $query ->selectTypeMap() ->addDefaults([ ‘alias’ => ‘integer’ ]); You can use any of the built-in data types, … Read more

Weird Behaviour with const_cast [duplicate]

The program has undefined bahaviour because you may not change a const object. From the C++ Standard 4 Certain other operations are described in this International Standard as undefined (for example, the effect of attempting to modify a const object). [ Note: This International Standard imposes no requirements on the behavior of programs that contain … Read more

Casting to generic type in Java doesn’t raise ClassCastException?

Java generics use type erasure, meaning those parameterized types aren’t retained at runtime so this is perfectly legal: List<String> list = new ArrayList<String>(); list.put(“abcd”); List<Integer> list2 = (List<Integer>)list; list2.add(3); because the compiled bytecode looks more like this: List list = new ArrayList(); list.put(“abcd”); List list2 = list; list2.add(3); // auto-boxed to new Integer(3) Java generics … Read more

PHP unexpected result of float to int type cast

This is because numbers that have a finite representation in base 10 may or may not have an exact representation in the floating point representation PHP uses. See >php -r “echo var_dump(sprintf(‘%.40F’, 39.3 * 100.0));” string(45) “3929.9999999999995452526491135358810424804688” Since int always rounds the number down, a small error in the representation makes the cast round it … Read more

Why does the Linq Cast helper not work with the implicit cast operator?

So why my explicit cast work, and the one inside .Cast<> doesn’t? Your explicit cast knows at compile time what the source and destination types are. The compiler can spot the explicit conversion, and emit code to invoke it. That isn’t the case with generic types. Note that this isn’t specific to Cast or LINQ … Read more

Are C-structs with the same members types guaranteed to have the same layout in memory?

Are C-structs with the same members types guaranteed to have the same layout in memory? Almost yes. Close enough for me. From n1516, Section 6.5.2.3, paragraph 6: … if a union contains several structures that share a common initial sequence …, and if the union object currently contains one of these structures, it is permitted … Read more