Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

mithrill

switch statement with const GUID

This topic is 5330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is not a DirectX spesific question but since the error occurs in my DirectX project ill ask it here anyway. Why cant i use a const GUID variable in a switch-case statement? im using switch to loop through a X-File to parse through the templates in the X-File. I know i just can use if statements instead, but i would rather use switch-case. By the way the error message i get is:"switch expression of type ''const GUID'' is illegal"

Share this post


Link to post
Share on other sites
Advertisement
Switch only works with ordinal types, anything that can be considered as a number basically. Are you saying switch (SomeConstant)? I don''t think switch allows a constant, since it won''t ever change. You could cast it to a long unsigned int though, and it would probably work. You''d just have to cast all of the cases to long unsigned ints as well.

Just a guess, let me know if it works!

Good luck,
Chris

Share this post


Link to post
Share on other sites
quote:
Original post by Supernat02
Switch only works with ordinal types, anything that can be considered as a number basically.
Nope. You can''t use a float as your case label. case labels must be integral, thus GUID is an invalid type.

quote:
Are you saying switch (SomeConstant)? I don''t think switch allows a constant, since it won''t ever change.
switch expects constant values, whether defined as const or resolved at compile time (ie, macros). You can''t use a runtime-resolved variable value as your case label either (most implementatinos of switch construct a jump table from the case labels; that is impossible if they aren''t known at compile time).

Share this post


Link to post
Share on other sites
Sorry, like I said, just a guess! Thanks for the corrections.

Oluseyi, you said "switch expects constant values, whether defined as const or resolved at compile time (ie, macros)". You mean the case part of it right?

I know you can put a constant in the switch statement and it compiles (doesn''t get you much though), but you can also put a runtime-resolved variable in the switch statement as well. The cases must always be constant...that makes sense. Just trying to get it all straight in my head.

Thanks,
Chris

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
const GUID *Type = GetObjectGUID(pDataObj);
switch(*Type)
{
case TID_D3DRMAnimationSet:
{
}
}

Does that not work?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!