Jump to content
AutoDesSys Forums
Sign in to follow this  
¢hris £und

What is wrong with this Statement? Code: beware..

Recommended Posts

if (topoType == (FZ_OBJT_TOPO_OWRE || FZ_OBJT_TOPO_CWRE || FZ_OBJT_TOPO_SURF) && LengthAbs_v_Perc== 0)


the Compiler says it is an invalid cast.    But doesn't everything cast to a boolean any way??


I played a little bit with O-o-Ops but get the same result.


I end up having to be more explicit

if ((topoType == FZ_OBJT_TOPO_OWRE || topoType == FZ_OBJT_TOPO_CWRE ||topoType == FZ_OBJT_TOPO_SURF ) && LengthAbs_v_Perc== 0)


Is there a shorter way?



Edited by Chris lund

Share this post

Link to post
Share on other sites

Surely what you're writing here first would be invalid in any programming language?


Basically you are comparing a bunch of values, resulting in true if they are and false if you don't. In your case they are topotypes but it could be anything really. As a thought experiment when you substitute integers for topotypes, I find it becomes easier to see that there is something strange going on:


if ( 1 == ( 2 || 3 || 4) && LengthAbs_v_Perc == 0)


The compiler will try to evaluate the ( 2 || 3 || 4) first as it lives between brackets but there isn't really an operation to evaluate there.


The other one you write makes more sense

if ((1 == 2 || 1 == 3 || 1 == 4) && LengthAbs_v_Perc == 0)


I don't think there is any way of writing it shorter. There is no shorter syntax and you can't shorten the variable names as they are predefined. If it's just about readability you could consider doing the comparisons before the if statement (but you already knew that):


in pseudocode:

bool comparison1 = topoType == FZ_OBJT_TOPO_OWRE

bool comparison2 = topoType == FZ_OBJT_TOPO_CWRE

bool comparison3 = topoType == FZ_OBJT_TOPO_SURF


if ((comparison1 || comparison2 || comparison3) && LengthAbs_v_Perc == 0)







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