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,981
questions
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
98
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
91
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
66
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
95
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
49
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. ...
-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
23
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 ...
0
votes
1
answer
61
views
Why are INumber<T>.CreateX(int n) so slow compared to implicit conversion for floats and doubles?
I'm working on a Maths library, and I'd like to be able to convert it to use the new INumber<T> interfaces in System.Numerics. The methods in here are often on hot paths and so would be good if ...
1
vote
1
answer
36
views
PowerShell - cast a variable type based on a variable definition
I've got a hashtable with variables. The source of this hashtable is an empty parameters.json (for deployment of Azure resources) converted to a hashtable.
For this question I have simplified this ...
5
votes
2
answers
152
views
Confused about casting and order of operations
This is a very specific problem and I haven't heard back from the author, so I thought I would throw this out and see if my sanity is intact or not.
This is in regard to this video regarding DMA on a ...
1
vote
1
answer
73
views
How to trigger implicit pointer conversion inline in a C macro?
Context
I have some functions to support using a custom memory allocator in my library:
void *(allocate)(struct allocator *allocator, size_t size, size_t alignment);
void (deallocate)(struct allocator ...
-1
votes
0
answers
16
views
Tensorflow is not casting my tensor as type float64 when I want it to, how do I fix it?
It's basically in the title. I'm trying to cast a tensor as a float64 for extra precision and so it can match what the data type of my bias is. However, despite calling the tf.cast function, it's ...