LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

type cast explanantion

Solved!
Go to solution
Highlighted

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!

Type cast.JPG

Best Regards,
Dhans Smiley Wink
Kudos are welcome Smiley Wink
Aspirant Labview Programmer (Labview 14) Smiley Wink
0 Kudos
Message 1 of 14
(1,361 Views)
Solution
Accepted by topic author dhans

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

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 2 of 14
(1,306 Views)

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…

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 3 of 14
(1,301 Views)

@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. 

Best Regards,
Dhans Smiley Wink
Kudos are welcome Smiley Wink
Aspirant Labview Programmer (Labview 14) Smiley Wink
0 Kudos
Message 4 of 14
(1,283 Views)

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…

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 5 of 14
(1,277 Views)

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?

Best Regards,
Dhans Smiley Wink
Kudos are welcome Smiley Wink
Aspirant Labview Programmer (Labview 14) Smiley Wink
0 Kudos
Message 6 of 14
(1,274 Views)
Solution
Accepted by topic author dhans

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"!

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 7 of 14
(1,244 Views)

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!

Best Regards,
Dhans Smiley Wink
Kudos are welcome Smiley Wink
Aspirant Labview Programmer (Labview 14) Smiley Wink
0 Kudos
Message 8 of 14
(1,236 Views)

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

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 9 of 14
(1,190 Views)

@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...

 

 

Spoiler

 

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

Spoiler
(which I have scheduled to sart at 2:00 this afternoon).

 

 

 

Ben 

Message 10 of 14
(1,174 Views)