casting

Why can't I implicitly convert a double to an int?

ε祈祈猫儿з 提交于 2020-07-03 07:02:17
问题 You can implicitly convert an int to a double: double x = 5; You can explicitly convert an int to a double: double x = (double) 5; You can explicitly convert a double to an int: int x = (int) 5.0; Why can't you implicitly convert a double to an int? : int x = 5.0; 回答1: The range of double is wider than int . That's why you need explicit cast. Because of the same reason you can't implicitly cast from long to int : long l = 234; int x = l; // error 回答2: Implicit casting is only available when

Why can't I implicitly convert a double to an int?

戏子无情 提交于 2020-07-03 07:02:03
问题 You can implicitly convert an int to a double: double x = 5; You can explicitly convert an int to a double: double x = (double) 5; You can explicitly convert a double to an int: int x = (int) 5.0; Why can't you implicitly convert a double to an int? : int x = 5.0; 回答1: The range of double is wider than int . That's why you need explicit cast. Because of the same reason you can't implicitly cast from long to int : long l = 234; int x = l; // error 回答2: Implicit casting is only available when

MISRA:Cast between a pointer to volatile object and an integral type?

不羁岁月 提交于 2020-06-29 09:01:31
问题 I have following code section: ----------header--------------------- typedef volatile struct REG_Base{ a; b; }REG_t #define address (0xFFF45556) ------------------------------------ --------Source----------------------- LOCAL REG_t *pToREG; pToREG= (REG_t *) address; ------------------------------------- I got on the last line the MISRA message " Cast between a pointer to volatile object and an integral type ". Any idea how to avoid this message? Thx! 回答1: MISRA has an advisory rule which

Conversion of Teradata sql to MYSQL sql

假装没事ソ 提交于 2020-06-29 05:17:36
问题 I want to convert Teradata query into MYSQL query. Datatype of START_TIME AND END_TIME is TIMESTAMP(6) Teradata query:- select START_TIME,END_TIME, (EXTRACT(DAY FROM (END_TIME - START_TIME DAY(4) TO SECOND)) * 86400) from base.xyz Result is like:- **START_TIME, END_TIME, CALCULATED_FIELD** 9/15/2017 16:22:52.000000 9/19/2017 15:14:02.000000 259,200 7/26/2014 07:00:04.000000 7/28/2014 12:55:55.000000 172,800 6/8/2018 16:59:19.000000 6/11/2018 09:56:23.000000 172,800 10/6/2017 17:52:06.000000

Conversion of Teradata sql to MYSQL sql

∥☆過路亽.° 提交于 2020-06-29 05:17:29
问题 I want to convert Teradata query into MYSQL query. Datatype of START_TIME AND END_TIME is TIMESTAMP(6) Teradata query:- select START_TIME,END_TIME, (EXTRACT(DAY FROM (END_TIME - START_TIME DAY(4) TO SECOND)) * 86400) from base.xyz Result is like:- **START_TIME, END_TIME, CALCULATED_FIELD** 9/15/2017 16:22:52.000000 9/19/2017 15:14:02.000000 259,200 7/26/2014 07:00:04.000000 7/28/2014 12:55:55.000000 172,800 6/8/2018 16:59:19.000000 6/11/2018 09:56:23.000000 172,800 10/6/2017 17:52:06.000000

Binary to binary cast with JSONb

情到浓时终转凉″ 提交于 2020-06-29 05:04:11
问题 How to avoid the unnecessary CPU cost? See this historic question with failure tests. Example: j->'x' is a JSONb representing a number and j->'y' a boolean. Since the first versions of JSONb (issued in 2014 with 9.4) until today (6 years!), with PostgreSQL v12... Seems that we need to enforce double conversion: Discard j->'x' "binary JSONb number" information and transforms it into printable string j->>'x' ; discard j->'y' "binary JSONb boolean" information and transforms it into printable

InvalidCastException while casting to OrganizationServiceContext

情到浓时终转凉″ 提交于 2020-06-28 03:42:27
问题 I have a early bound class generated by CrmSvcUtil: public partial class CustomerCrmServiceContext : Microsoft.Xrm.Sdk.Client.OrganizationServiceContext { ... ... } Then I have a class like this (short version): public abstract class PluginClass<T, C> : PluginClassBase<T> where T : Entity where C : OrganizationServiceContext { protected new C ServiceContext; protected PluginClass(IOrganizationService service, ITracingService tracer) : base(service, tracer) { ServiceContext = (C)base

Casting to a Tuple<object,object>

十年热恋 提交于 2020-06-27 19:22:01
问题 Consider this chunk of code where I'm testing an unknown variable that could be an int, MyObj, or Tuple, and I'm doing some type checking to see what it is so that I can go on and handle the data differently depending on what it is: class MyObj { } // ... void MyMethod(object data) { if (data is int) Console.Write("Datatype = int"); else if (data is MyObj) Console.Write("Datatype = MyObj"); else if (data is Tuple<object,object>) { var myTuple = data as Tuple<object,object>; if (myTuple.Item1

Casting to a Tuple<object,object>

眉间皱痕 提交于 2020-06-27 19:21:12
问题 Consider this chunk of code where I'm testing an unknown variable that could be an int, MyObj, or Tuple, and I'm doing some type checking to see what it is so that I can go on and handle the data differently depending on what it is: class MyObj { } // ... void MyMethod(object data) { if (data is int) Console.Write("Datatype = int"); else if (data is MyObj) Console.Write("Datatype = MyObj"); else if (data is Tuple<object,object>) { var myTuple = data as Tuple<object,object>; if (myTuple.Item1

Casting an address of subroutine into void pointer

佐手、 提交于 2020-06-27 17:09:04
问题 Is it okay to cast function location with void pointer though function pointers size is not always the same as opaque pointer size? I already did search about opaque pointers , and casting function pointers . I found out function pointers and normal pointers are not the same on some systems. void (*fptr)(void) = (void *) 0x00000009; // is that legal??? I feel I should do this void (*fptr)(void)= void(*)(void) 0x00000009; It did work fine , though I expected some errors or at least warnings I