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.
casting
19,986
questions
1
vote
2
answers
43
views
Is there documentation somewhere for such type casting?
class A {
int b;
int c;
A(this.b, this.c);
}
void testFunc(Object param) {
print((param as A).b);
print(param.c); //is there documentation somewhere? Why is there no need type casting?
}
...
-1
votes
0
answers
45
views
Are these explanations about "checked" and "unchecked" narrowing reference conversion in Java right? [duplicate]
I'm learning "unchecked" and "checked" narrowing reference conversions in Java. Unfortunately, there is not many docs on that topic (I only found them in Java SE 11 Oracal docs). I ...
1
vote
1
answer
128
views
Specify the type of a C++ pointer at runtime (generic pointer)
I am developing a simulation code written entirely in C++ where we use double precision for all computations. Now I want to make it configurable to use single precision if the user wants. The problem ...
0
votes
1
answer
114
views
Why does defining the elements of the array b is required to get the desired output
I recently learnt about typecasting pointers. So I played around, and made this bad code:
#include <stdio.h>
int main()
{
int* a;
char b[]= "Hye";
a = (int*)&b;
*a='...
0
votes
0
answers
14
views
Declaring an interface property as a derived type [duplicate]
Currently I have a series of services/repos that are allowing a generic of a custom type. I want to add a generic list to that interface such that when a class inherits the interface it can apply a ...
0
votes
3
answers
101
views
How to declare a type for function pointer variable in C without using "typedef"?
I have a function called add which adds two integers as shown below:
int add(int a, int b){
return a + b;
}
and I wanted to create a pointer to my function named a and call my function using it
...
0
votes
1
answer
93
views
Casting enum variant data pointers to enum pointers in Rust
The background:
I've encountered a situation where I have two tree datastructures with different internal and leaf node types. I want to maintain a vector which holds pointers to the leaves using a ...
-1
votes
1
answer
70
views
How can I cast between f32 and u32 without changing the bits?
So i'm making a virtual machine which takes in a sequence of 32 bits (so multiple batches of 32 bits) and they're represented as u32s, but in reality the number could be a f32 but just wrapped in a ...
1
vote
1
answer
99
views
Is it allowed to cast a pointer of first member to the enclosing type?
According to the C Standard, it is allowed to cast a pointer to a struct to a pointer of the type of the first member of this struct.
However, is it allowed to do the opposite?
Consider the following ...
3
votes
1
answer
51
views
SonarQube requesting explicit cast on the result of the shift operator
I have a ton of similar issues reported by SonarQube:
m_buffer[0] = static_cast<uint32_t>(headerByte0 << 8);
Where m_buffer is an array of uint32_t, headerByte0 is uint8_t. ...
-5
votes
2
answers
300
views
Why `emplace()` without arguments returns 0? [duplicate]
Below is the example code snippet:
#include <optional>
#include <iostream>
int main()
{
std::optional<unsigned> check = 200;
std::cout << check << std::endl;
...
-2
votes
1
answer
69
views
Hot to cast using Class returnType obtained through reflection?
I am using reflection to get return type of method which is String.
When I invoke function I need to cast return value to String.
How can I do that without explicitly using String and instead to use ...
0
votes
0
answers
27
views
Is it possible to point dynamic expression after AS operator in Kotlin [duplicate]
I have a problem: kotlin let us make statements like this:
val castedObject = otherObject as CastedObjectClass
and we always hardcode this CastedObjectClass, in other words, statement after the as ...
0
votes
0
answers
36
views
InvalidCastException with EnvDTE.DTE but only on some machines?
I have this code to start an instance of TwinCAT (which is basically VisualStudio) and get its DTE interface.
Type t = Type.GetTypeFromProgID("TcXaeShell.DTE.15.0");
if (t == null) return ...
0
votes
0
answers
29
views
how to implement flutter video cast to TV
I'm using flutter_vlc_player to cast a video to a device, but I'm encountering an issue where it says "device not found." Here's the code snippet where I attempt to get renderer devices and ...