12-16-2016 12:14 AM
Hi, all. I am in need of help to understand the operation of type cast and what is the technical meaning of the words 'flattening' and 'unflattening' that is used in 'type cast' explanation. Thanks in advance!
Solved! Go to Solution.
12-16-2016 02:19 AM
In the variant function panel you have Flatten and Unflatten functions (try 'em out). What they do is basically interpret any data as a string (flatten) and try to interpret a string as a specific data type (unflatten). In C and derivates it'd be (void*) data, i.e. interpret any data as pure general data and not type specific data.
Does that help?
/Y
12-16-2016 02:27 AM
Hi dhans,
casting means to change a datatype without changing the underlying data!
Example:
You have a SGL with a value of "-4". This value is stored in memory using the bytes "C0 80 00 00".
When you typecast this SGL value to an U32 you get the decimal value "3229614080", which is still the same bytes "C0 80 00 00" in memory…
12-16-2016 03:42 AM
@GerdW wrote:
Hi dhans,
casting means to change a datatype without changing the underlying data!
Example:
You have a SGL with a value of "-4". This value is stored in memory using the bytes "C0 80 00 00".
When you typecast this SGL value to an U32 you get the decimal value "3229614080", which is still the same bytes "C0 80 00 00" in memory…
Hi GerdW,
I am lit bit confused. In your statement, only the hex value " C0 80 00 00 " which is an address of memory will be converted to U32 as 3229614080. Then how can I get that modified " -4 " as an output from type cast vi instead of address.
12-16-2016 03:48 AM
Hi dhans,
only the hex value " C0 80 00 00 " which is an address of memory
Why do you think of "addresses" here? I talk about values/data!
These 4 bytes can represent
- an array of 4 I8/U8 values
- an array of 2 I16/U16 values
- a I32/U32/SGL value
- a string of 4 chars
- many other options
But still in memory you always have those 4 bytes!
Typecasting means to reinterprete the bytes in memory using different datatypes…
12-16-2016 04:00 AM
Hi GerdW,
I got your point. What you have said is that 4 bytes can be of any data type that can be cast but the data " -4 " will be " -4 " only. No change in that data. Am I right?
12-16-2016 04:38 AM
Hi dhans,
but the data " -4 " will be " -4 " only. No change in that data. Am I right?
Not really!
The underlying bytes in memory will not change, but the interpretation of these bytes may/will differ!
Interpreting the bytes mentioned before as SGL will result in -4, but when typecasting the very same bytes to U32 you get "3229614080"!
12-16-2016 05:13 AM
Hi GerdW,
Thanks alot. I understand. Labview stores SGL " -4 " as "C0 80 00 00" and this will be interpreted in different types of data. Thanks a lot man!
12-16-2016 10:17 AM
A good analogy is languages. The same letters can mean different things depending on language, but the data is the same. Type casting is basically saying 'interpret this text in language X' instead.
'well' has atleast 3 interpretations in english alone, so type casting is like saying 'it's not the object, but the adjective'
/Y
12-16-2016 11:26 AM - edited 12-16-2016 11:40 AM
@Yamaeda wrote:
A good analogy is languages. The same letters can mean different things depending on language, but the data is the same. Type casting is basically saying 'interpret this text in language X' instead.
'well' has atleast 3 interpretations in english alone, so type casting is like saying 'it's not the object, but the adjective'
/Y
Forums broke my emoticons! Trying out a new one...
I followed you right up the the end when my brain slipped gear thinking "Adective Oriented Programming".
I need a vacation. I think I will just take the rest of the year off
Ben