Switch...Case problem
jjames
Posts: 2,908
Here's my switch / case:
Commenting out the numerics allows it to compile. With it in there I get the following message:
Edit - sorry for the lines not lining up . . . my tab/spacing settings sometimes freaks out when copying & pasting it seems.
switch(s_splitOutput[2]) { case '0' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E0" case '1' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E1" case '2' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E2" case '3' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E3" case '4' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E4" case '5' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E5" case '6' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E6" case '7' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E7" case '8' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E8" case '9' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E9" case 'ENTER' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A0" case 'INFO' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A1" case 'ACTIVE' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A2" case 'LIST' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A3" case 'BACK' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A4" case 'DASH' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A5" case 'SELECT' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$C3" case 'POWER_ON' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$C5" case 'PAUSE' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B0" case 'REWIND' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B1" case 'PLAY' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B2" case 'STOP' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B3" case 'FFWD' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B4" case 'RECORD' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B5" case 'REPLAY' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B6" case 'ADVANCE' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B7" case 'RED' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EA" case 'YELLOW' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EB" case 'GREEN' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EC" case 'BLUE' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$ED" case 'MENU' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$F7" case 'FORMAT' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$F8" case 'POWER_OFF' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D0" case 'CHAN+' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D1" case 'CHAN-' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D2" case 'GUIDE' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D3" case 'EXIT' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D4" case 'POWER' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D5" case 'PREV' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D6" case 'RIGHT' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9A" case 'LEFT' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9B" case 'UP' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9C" case 'DOWN' :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9D" }
Commenting out the numerics allows it to compile. With it in there I get the following message:
ERROR: (0): C10580: Internal Error: Major system fubar occurred during code generation.Okay - not really, but I do get a Major system error. What give? Doesn't matter where the numerics in the switch/case are, or even using decimal or hex values in their place.
Edit - sorry for the lines not lining up . . . my tab/spacing settings sometimes freaks out when copying & pasting it seems.
0
Comments
I seem to remember a bug with the SWITCH/CASE and numerics - any one have an idea?
Jeff
I'm sticking with the SELECT/ACTIVE which seems to be working.
discussion nullified and lulz kept intact
I think it will compile if you move the single characters 0-9 to the bottom of the switch (after DOWN.)
That said, I believe your assessment may be half wrong since moving to the end worked. Thanks Joe!
K&R
GNU / Gnits
Large organizations known for software (Microsoft, Google, etc)
Working professional programmers
List goes on - search for it?
Some examples
http://en.wikipedia.org/wiki/Switch_statement
But this thread wasn't originally about this, was it? Not sure why you took such offense and had to fire off such a response. Regardless, if you think code "beauty" is in the eye of the beholder and needs to be defended, then thankfully I don't work with you, and you may want to consider not posting terrible code samples when asking for help. For what it's worth, your intense data duplication in that switch makes me chuckle.
Back on topic, thanks Joe Herbert, starting with a two-or-more character string does fix the problem (at least as far as compiling it goes). Thanks for pointing that out.
ie
Sorry, just bothered to read Joe's post which answered this anyway.
The feeling is mutual.
My apologies Grand Master. Will you please teach me? I'm dying to learn from someone who feels AMX is junk and wants to view their Linux code for the touch panels in order to start his own control system company to compete with AMX (now that makes me chuckle.) Hurry up will you? I'm tired of your pompous "ace" posts.
By the way - how's that song lyric go? Oh yeah, "first came an action and then a reaction, but you can't switch em' round for your own satisfaction"
lol
I should come up with a term for this AMX dealer and programmer "someone will steal your stuff and make a company from it" mentality. (fwiw, AMX is obligated to give me, and you, source for certain components, such as the Linux kernel.)
You wouldn't like it if someone stole your code and distributed it without permission, right? That's copyright infringement. AMX is doing just that and you seem to be fine thinking I have a complex for it.
Do some reading, it might do you some good:
http://www.gnu.org/licenses/gpl-2.0.txt
I know you can read, but if you have comprehension issues, have someone explain Section 3 to you.
Are you a complete idiot? Sources to the kernel, Busybox, etc. isn't source to vtg, the actual touchpanel software.
I love you.
That is my experience with Switch...Case. single characters always go after multiple character cases, although I don't think you need to have the longest case first.
If I remember correctly a switch...case in NetLinx will cast all case values to the smallest type that will preserve the value of the first case statment. For example:
Very true, and well put - the comment wasn't necessarily focused at your post though.
P.S. regarding the TP firmware, if it is GPLv2 true is absolutely 100% within his rights to request, and is entitled to the source of any components which fall under that license, nothing complex about it.