Questions tagged [casting]

Casting is a process where an object type is explicitly converted into another type if the conversion is allowed. This process might lead to a change in value.

Filter by
Sorted by
Tagged with
0
votes
2answers
21 views

TCL: A variable stores a hex value that represents a floating point number, how can this be printed on screen as a float?

The 0x3f800000 represents 1.0 in single precision floating maths. I tried this but could not get the correct result from the program: set x 0x3f800000 set y [expr double($x)] puts $y I just want to "...
0
votes
1answer
31 views

How to make a compiler interpret a memory array with chunks of 8 bit (or diff in other case) while type casting void* to unsiged char* array in C

i am writing a program in which my data from a unsigned int* buffer needs to be converted to a data array of unsigned char* array, so that i can use it further. But if my buffer is initialized to 0, ...
0
votes
1answer
40 views

Error converting data type nvarchar(50) to numeric

I have a price column with the type of NVARCHAR(50). Inside of this, I have data like 123,22 as a string and goes on. They are now string and I want to convert them to decimal(18,2) and I am trying to ...
0
votes
0answers
19 views

C++ Invalid Argument to stof()/stoi() (std::invalid_argument: stoi: no conversion)

I have a program where I attempt to take a string value out of a vector and convert it into a float. The string is guaranteed to be a numerical value based on how I'm parsing the input data. When I ...
5
votes
2answers
56 views

When returning the difference between pointers of char strings, how important is the order of casting and dereferencing?

For educational purposes (yes 42 yes) I'm rewriting strncmp and a classmate just came up to me asking why I was casting my returnvalues in such a way. My suggestion was to typecast first and ...
0
votes
1answer
29 views

Java Casting To Parent Type and ignore child type attributes

I am trying to cast a child type to a parent type. The thing is since the child class extends parent class, when casting to the parent type child specific attributes are also kept. I would like to ...
0
votes
1answer
44 views

memcpy long long int (casting to char*) into char array

I was trying to split a long long into 8 character. Which the first 8 bits represent the first character while the next represent the second...etc. However, I was using two methods. First , I shift ...
18
votes
1answer
263 views

Why in C++ do static_cast<unsigned> of negative numbers differ if the number is constant or not

What's the C++ rules that means equal is false?. Given: float f {-1.0}; bool equal = (static_cast<unsigned>(f) == static_cast<unsigned>(-1.0)); E.g. https://godbolt.org/z/fcmx2P #...
0
votes
0answers
25 views

cast string to date (string may empty spaces in the DD position)

I have a column with strings which look like this: '201201 ' '19880324' ' ' '176512 ' I need to cast them to date, but I cannot do it directly with to_date('string', 'YYYYMMDD') since some ...
1
vote
1answer
47 views

Why is a cast to an `IEnumerable<T>` allowed but to a `List<T>` in a generic method [duplicate]

I'm pretty sure I'm missing the obvious answer, but why this: public static void Foo(IEnumerable<string> strings) { } public static void Bar<T>(IEnumerable<T> ts) { Foo((...
-1
votes
2answers
50 views

How to cast a void pointers to float to be used in a function in C?

I changed a code so that it could accept floats in a void pointer cast and use it in a function but while it was working with ints before making adjustment to it made the "incompatible types when ...
1
vote
4answers
52 views

Why when casting in inline with assign a value it compiles?

This is my Example code class Example{ public static void main(String args[]){ short s = 100; byte b = s; // this is compile time error because of no casting ...
1
vote
0answers
31 views

Perl Rose::DB - is there any CAST or CONVERT function to use in relationship clause?

Is there any cast/convert function in Rose::DB e.g. to cast a varchar column to integer? As reference: https://metacpan.org/pod/Rose::DB::Object::QueryBuilder I need use join on two tables as below. ...
3
votes
1answer
58 views

Extracting bytes from a 32 bits number

This is not important and should be quite simple, I just don't understand what I'm doing wrong. The story behind this is that I'm playing with tinyNeoPixel lib on the attiny85, and I'm trying to dive ...
0
votes
1answer
25 views

How to re-cast char* to integer after using sprintf_s()?

This is my casting from int to char*: char* str = malloc(sizeof("0000")); int int_ = 10; sprintf_s(str, sizeof("0000"), "%04d", int_); //str == "0010" And I want to re-cast str to int back (int_new =...
0
votes
0answers
6 views

Global overflow checking vs the local overflow checking precedence

Which checking configuration is considered first during the compilation when deciding whether to allow the overflows or not: global or local? E.g. if I have the following code: unchecked { Byte ...
-1
votes
1answer
18 views

passing a variable as a parameter to varchar() as in cast(column1 as varchar(@variable))

Using SQL Server 2014. As a challenge someone asked me to return 113.05 as 0.05 in a select statement. I put forth the following: declare @temp1 table (value1 numeric(5,2)) insert into @temp1 (...
0
votes
2answers
48 views

type name is not allowed in C

I'm trying to use ADC with DMA using STM32F407. I want to set memory adress of ADCValue to DMA stream x memory 0 address register. But i get this error: type name is not allowed This part is in ...
-1
votes
2answers
49 views

How to cast Class<?> to Class<? extends X>? [duplicate]

I have a class A saved as Class<?> which I know is a subclass of B and have to cast this into a Class<? extends B>. But my code does not compile: Class<?> c = ... if (c.newInstance()...
-1
votes
1answer
19 views

How to cast an object which consists of integer to corresponding character in ascii?

I tried ''' Object b = 3; char cdd = (Character) b; System.out.print(cdd); ''' but it has the following error. Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be ...
2
votes
0answers
53 views

why when final variable initialize value inline that variable compatible to smaller data type without cast? [duplicate]

This is my Example java code. class Example{ public static void main(String args[]){ int x = 65; final int y = 65; final int z; z = 65; char ch; ch ...
2
votes
2answers
79 views

Casting numerical value to VARCHAR2 throws ORA-03113

When we run statements against an Oracle 12c Enterprise Edition Release 12.2.0.1.0, which contains casts of numerical values to VARCHAR2(4000 char), we receive an ORA-03113 end-of-file on ...
1
vote
1answer
33 views

How to compress a numpy array of type bool to uint8 with 1/8 of the size

I want to 'compress' a large array of booleans of size (Ny, Nx). What is the fastest way to I convert them into a uint8 array of size (Ny, Nx//8) where every boolean plane is stored in the next bit of ...
0
votes
1answer
46 views

PostgreSQL - Casting JSON string to INTERVAL returns incorrect value

I am observing a weird behaviour on Postgres server when casting a JSON string into INTERVAL type. I tried it out on Postgres v9, v10, v11 and got the same results on each. Example: select '{"...
0
votes
0answers
42 views

Reinterpret a vector of unsigned long long int into a vector of unsigned shorts in place

This task might seem esoteric and dangerous but it's for some highly optimized code (admittedly I yet have to do actual benching). However I have an std::vector<unsigned long long int> and want ...
0
votes
1answer
29 views

Correct syntax for uniform initialization of temporary of type with space in name like unsigned int

I'm trying to pass x of type T to a function foo which expects unsigned int, and I'm not sure what T is because it's a typedef declared in some other module. Both foo and T are not something I can ...
0
votes
1answer
43 views

What is the difference between these two options for converting Swift Dictionary to NSMutableDictionary?

In my project I have a dictionary of type [String: AnyObject] and am converting it to NSMutableDictionary to be compatible with some Objective C code in the project. I started using the below ...
0
votes
1answer
71 views

Is there a way to cast a generic list / dictionary to any implemented interfaces of the containing objects

Is there a way to cast a generic collection to any of the interfaces being implemented by the stored objects ? So the idea would be to have the possibly to expose the underlying dictionary or list ...
0
votes
2answers
42 views

Text array of integers for joining tables in Postgres

I have two tables Entity House In house table, there is a column entity_id of type text. And entity_id will store multiple house ids. So it will look like entity_id (text) ------------------ [1,2] ...
1
vote
2answers
29 views

Cast based on variable

I am trying to cast based on the value of a variable, ultimately to be able to actually test to see if $castFrom is of the $castTo type. I can of course do it with a switch like this $castTo = '[xml]'...
1
vote
1answer
17 views

Why can typescript infer non-null types using double negation but not with the boolean constructor?

The example below illustrates the fact that typescript can infer that someVal is not null when casting it to a boolean using double negation (!!), but not when casting it (more explicitly) using the ...
0
votes
1answer
25 views

How can I cast the return from Utilities.formatDate(new Date(), “EST”, “HH”); to an integer?

I have tried a million ways with no luck. I know I could use a date object and getHours method but I need it to be EST timezone specific. function test () { var hour = Utilities.formatDate(new ...
-5
votes
3answers
85 views

Can I change the datatype of previously declared variable in C?

I have declared a string and using malloc function I allocated the memory... Now I want to change this string into a floating type. char *str; str=malloc(sizeof(char)*10); strcpy(str,"123.4"); float ...
0
votes
2answers
79 views

Error to convert varchar to float using c#

I have a problem , i'm trying to do operations between values recorded(type float) in table of data , the problem is when i try to update value(result of the operation in textbox) in datable using ...
0
votes
0answers
27 views

Pointer to pointer to derived class instance [duplicate]

class Base { }; class Derived: public Base { }; void main() { Derived* d; Base* b = d; // it's ok Base** bb = &d; // compilation error (different on different compilers) } Is there ...
0
votes
0answers
25 views

List<Type> converted to IEnumerable<Interface> and then to List<Interface> is null [duplicate]

forgive me if the title is unclear but I couldn't find another way to describe what I encountered. I ran into a problem when writing code that is analogous to the following : using System; using ...
0
votes
0answers
12 views

Casting Session object into a different object of another unreferenced assembly in C#

I want to cast session data into a different object class. I am storing the class object which is referenced into different Assembly. namespace Assembly1 { public class A { public ...
1
vote
3answers
21 views

EditText is a TextView when checking type

I'm using this line to check on a number of views in my app and get the values associated with them, as input by the user. Every other view (odd) is a text view that's used as a title for the ...
29
votes
6answers
2k views

Why is this claimed dereferencing type-punned pointer warning compiler-specific?

I've read various posts on Stack Overflow RE: the derefercing type-punned pointer error. My understanding is that the error is essentially the compiler warning of the danger of accessing an object ...
0
votes
0answers
71 views

Type conversion with generics and inheritance

I present you the problem, The problem comes from a NullReferenceException, due to the fact that when I convert my DofusClient object to TClient via the As operator that returns to me null(bad cast ...
0
votes
1answer
34 views

Android app crashes when trying to connect to CC receiver

Some of our users are experiencing issues with connection to the Chromecast receiver. When they select a CC device in the app from the list of available devices the app crashes. Here is the stacktrace ...
0
votes
1answer
24 views

Casting string to integer in mvel

How to cast string to integer in MVEL Props['MyInteger'] = java.lang.Integer.ParseInt('//xpath to some string') Other java typing works in my code. for example Props['MyArrayList'] = new java.util....
1
vote
1answer
35 views

Casting keeps on getting errors

I have a CSV with the following data (no header) 12,2010,76.5 2,2000,45 12,1940,30.2 and I'm reading the data into a List<List<object>>. To know what's in each line and column / row I'm ...
1
vote
3answers
58 views

Set values in a casted object Swift

I have a protocol Food which contains a name and a price. The struct Fruit is implementing this protocol and has another specific variable named color. A class Fridge (my ViewController) can ...
0
votes
2answers
73 views

Not understanding F# syntax with type conversion

This works: let a = 3 let b = string b let c = a |> string but: let a = string j.SelectToken("hello") doesn't work, while let a = j.SelectToken("hello") |> string works. why is that?
0
votes
1answer
30 views

how to cast or set an object of type id to another type like UIImageView or UIView

In the below code, I iterate through entries and they might be of type UIView or UIImageView. I want to do check if the uiComponent is of either the mentioned types, and then I want to proceed using ...
0
votes
0answers
40 views

Why does Qt c++ app not throw exception on instantianting an attribute on object that does not have it?

I'm developing an app on QtDesigner.I've Promoted few QPushButtons to MyButton. MyButton simply extends QPushButton and add to it an int attribute. Working on the project I noted I forgot to promote ...
-4
votes
0answers
45 views

Explain how line 3 and line 4 are illegal [duplicate]

class Example { public static void main(String args[]) { byte b1=10; // line 1 byte b2=20; // line 2 byte b3=b1+b2; // line 3 short s1=b1+b2; // line 4 int x1=b1+...
0
votes
0answers
28 views

Using cast in Mysql has made my stored procedure too slow. Is there an alternative to 'CAST' which is faster?

My stored procedure was working fine until I had to use CAST in it which has made my stored procedure too slow. Is there an alternative? I am using 'CAST' as such - CAST(created_by AS CHAR(20))= CAST(...
1
vote
2answers
58 views

Is it possible to avoid unchecked casting when calling `clone()`?

This is a contrived example to illustrate the problem. I know there are ways around this that don't generate compiler warnings and you can also disable the warning. I'm wondering if this is possible ...