Skip to main content
GameDev.net gamedev.net
🔒 Locked

switch statement with const GUID

Started by mithrill Jan 11, 2004 at 3:00 PM 4 replies 4.3k views
Original Post
mithrill
mithrill
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"
Supernat02
Supernat02
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
Chris ByersMicrosoft DirectX MVP - 2005
Oluseyi
Oluseyi
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).
Supernat02
Supernat02
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
Chris ByersMicrosoft DirectX MVP - 2005

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.