Jump to content
Sign in to follow this  
probiner

preprocessors to decide variable type?

Recommended Posts

One thing that throws me off the road with VEX is issues with operations not being overaloaded/able or not have the ability to drive the type cast of a variable. Kills abstractness and makes for some cumbersome code.
I've used in the past a trick to get the variable assignment to be programmatically driven(float, vector...etc) instead of scooped in a sucession of else ifs that lead to duplicated code:
 

if(caracteristic == 0){
  float var = attrib(0,class, name, @elemnum) ;
  < code body>
}
else if(caracteristic == 1){
  vector2 var = attrib(0,class, name, @elemnum) ;
  < code body>
}
else if(caracteristic == 2){
  vector var = attrib(0,class, name, @elemnum) ;
  < code body>
}
....
....
....


Instead just have

`chs("type")` var = attrib(0,class, name, @elemnum) ;
< code body>


Which will result in var being casted based on parameter, and also not being scoped and therefore no code duplication for each case.

Now while seems great, I've noticed it takes way more time to cook than the else ifs way.-

Therefore I was wondering if there is a way to do this driven variable assignment with preprocessors. The code still might look ugly but at least the execution part will be a single one for all types.
 

#define var 100.0

This for example sets var as a float. But I wonder how I can inform it which variable type it should have.


Thanks

 

Edited by probiner

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  

×