Jump to content
News about the LabVIEW Wiki! Read more... ×
Sign in to follow this  
infinitenothing

Making Coerce To Type a little safer

Recommended Posts

Coerce to type is useful for getting nontypedeffed data into a typedef form but there's a small problem of type safety. For example, if you try and coerce an I32 to a U8, the value will silently wrap without even so much as a coercion dot.

But in recent versions of LV, we have something to ensure a little safety— "Assert Structural Type Match"

And fortunately, for this use case, it's not so sensitive as to disallow typedeffed data from matching it's plain counterpart so we can use it to enforce a runtime error if someone wires an I32 up. And, to make this new function more convenient, you can wrap it up in a VIM. 

TypeDef Snippet.png

Edited by infinitenothing

Share this post


Link to post
Share on other sites

Why would there be a coercion dot on the input of a function whose name implies it is being used for a coercion?  The fact that a coercion is taking place is obvious due to the presence of the node for doing the coercion......

That aside, I think the addition of type safety would be a welcome additional function.  But does your function allow us to coerce a U8 to a U16 for example?  Here no data is lost and it should be completely safe (under the assumption the programmer knows what they are doing).

Edited by shoneill
spelling

Share this post


Link to post
Share on other sites

No, it will break if you try and convert a U8 into U16 so it's a little conservative in that manner.  The programmer would be expected to do the U8 to U16 upstream to "get rid of the broken arrow". It would be really cool if there was a way to allow all the "safe cooerces".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.