Jump to content

preprocessors to decide variable type?


probiner

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...