Thread: switch case error. Can anyone help?

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    230

    switch case error. Can anyone help?

    switch case error. Can anyone help?

    Code:
    void sig_handler(int signo){
    	switch(signo){
    		case SIGALRM:
    			flag = getpid();
    			switch(flag){
    				case parent_PID:
    					p_realt_secs++;
    					break;
    				case child1_PID:
    					c1_realt_secs++;
    					break;
    				case child2_PID:
    					c2_realt_secs++;
    					break;
    				default:
    					break;
    			}
    			break;
    		case SIGVTALRM:
    			flag = getpid();
    				switch(flag){
    				case parent_PID:
    					p_virtt_secs++;
    					break;
    				case child1_PID:
    					c1_virtt_secs++;
    					break;
    				case child2_PID:
    					c2_virtt_secs++;
    				break;
    				default:
    					break;
    				}
    			break;
    		case SIGPROF:
    			flag = getpid();
    				switch(flag){
    				case parent_PID:
    					p_proft_secs++;
    					break;
    				case child1_PID:
    					c1_proft_secs++;
    					break;
    				case child2_PID:
    					c2_proft_secs++;
    					break;
    				default:
    					break;
    				}
    			break;
    		default:
    			break;
    	}
    }
    output:
    Code:
    kernel_system.c: In function ‘sig_handler’:
    kernel_system.c:26: error: case label does not reduce to an integer constant
    kernel_system.c:29: error: case label does not reduce to an integer constant
    kernel_system.c:32: error: case label does not reduce to an integer constant
    kernel_system.c:42: error: case label does not reduce to an integer constant
    kernel_system.c:45: error: case label does not reduce to an integer constant
    kernel_system.c:48: error: case label does not reduce to an integer constant
    kernel_system.c:58: error: case label does not reduce to an integer constant
    kernel_system.c:61: error: case label does not reduce to an integer constant
    kernel_system.c:64: error: case label does not reduce to an integer constant

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    My guess is that your case labels (parent_PID, etc) are integer variables. Case labels do not work with variables.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    Right! thanks...i just change it into if else{ }

  4. #4
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    switch/cases only work with constants.
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    i got it thanks...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. confused
    By alexbcg in forum C Programming
    Replies: 2
    Last Post: 12-07-2010, 05:42 AM
  2. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  3. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  4. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  5. rand()
    By serious in forum C Programming
    Replies: 8
    Last Post: 02-15-2002, 02:07 AM