Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8603143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:15:17+00:00 2026-06-12T02:15:17+00:00

I am writing code for AVR ATmega32-A microcontroller. I am using switch case as

  • 0

I am writing code for AVR ATmega32-A microcontroller. I am using switch case as shown below.

  unsigned char Command;
  unsigned int  Param;

  void runCom(void){

    switch(Command){

        case(NO_COM):
            Command = 0;
            break;

        case(INF):
            printf("\r\n\r\n");
            printf("university\r\n");
            printf("sweden\r\n");
            printf("Ver. 1.0A\r\n");

            Command = 0;
            break;

        case (DB):                        
            Command = 0;
            break;


        case(CLEARM):
            Command = 0;
            break;

        default:
            Command = 0;
            break;   
    }
}

the above code is working but now i want to add one more case in that switch like as shown below.

 unsigned char Command, Command1;
 unsigned int  Param;
 void runCom(void){

    switch(Command){

        case(NO_COM):
            Command = 0;
            break;

        case(INF):
            printf("\r\n\r\n");
            printf("university\r\n");
            printf("sweden\r\n");
            printf("Ver. 1.0A\r\n");

            Command = 0;
            break;

        case (DB):                        
            Command = 0;
            break;



         case(ADC):
             printf("ADC Value",ReadAd()); 

             printf("Enter Amplification stage");

                       switch(Command1){

                              case(stage1):
                                    PORTC=0x00;
                                    DDRC=0xC0; 
                                    printf("ADC Value",ReadAd());
                                    Command1 = 0;  
                                    break;

                                    case(stage2):
                                    PORTC=0x00;
                                    DDRC=0x03; 
                                    printf("ADC Value",ReadAd());
                                    Command1 = 0;  
                                    break;
                                   }    
            Command = 0;
            break; 

        case(MEM):
            Command = 0;
            break;

        case(CLEARM):
            Command = 0;
            break;

        default:
            Command = 0;
            break;   
    }
}

I am getting error like

   undefind symbol 'ADC'
   undefind symbol 'stage1'
   undefind symbol 'stage2'

then i have declared like this

unsigned char Command, ADC, Command1, stage1, stage2;
  unsigned int  Param;

now i am getting error like

constant integral expression required at line case(ADC)
constant integral expression required at line case(stage1)
constant integral expression required at line case(stage2)

so please can any one suggest me how to overcome this error. I haven’t declared WGP, WGF, INF any where but I am not getting “undefined symbol of WGF, WGP, INF. why this error occurring for ADC only. i have fallowed same switch case rules as i used before. any suggestions appreciated.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:15:18+00:00Added an answer on June 12, 2026 at 2:15 am

    The values you use in the cases of a switch statement must be compile-time constants. That is, they must have fixed values that are known to to the compiler at compile time.

    There are four main ways to do this.

    1. You can use a constant literal (a number).
       case 42:
    

    Note that using unnamed values (“magic numbers”) isn’t recommended because it doesn’t document the code in any way, and makes the code fragile (what if you need to change the value to 43 in five different places and forget one?)

    1. You can use a preprocessor constant.
       #define COMMAND_CODE 42
       ...
    
       case COMMAND_CODE:
    

    That’s better because if you need to changet the command code value to 43 you only have to change the #define (which should only occur once, in a header file).

    1. You can use an enum.
       typedef enum { COMMAND_ON=42, COMMAND_OFF=2, COMMAND RESET=77 } command_codes:
       ...
    
       case COMMAND_ON:
    
    1. In C++, if your compiler is reasonably modern, you can use a constant:
       const int magic_number = 42;
    
       case magic_number:
    

    (Note that the switch value shown in a case statement does NOT need to have parentheses around it.)

    From the code you have shown, it seems that you have defined Command, ADC, etc., as variables (rather than as constants). In this case the compiler can’t know what value those variables will have at execution time when it compiles the code. The language specifies that case values must be known at compile time so that the compiler can generate fast code (faster then a whole series of if … else if … else if statements).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am writing code in vb.net .am using select statement in oracle command . when
Writing code with implicit cast generates CS0266 . Dictionary<Int32, string[]> d1 = new Dictionary<int,
Background I am writing code in VS 2010, .NET 4, C#. Also, in case
I sometimes find myself writing code like this: someFunc :: Foo -> Int someFunc
Is writing code for JavaFX 2.0 using Visage essentially the same as if you
Often times when writing code, I find myself using a value from a particular
I am writing C code for an AVR chip. The code is heavy on
I frequently find myself writing code like this: List<int> list = new List<int> {
I find myself writing code that looks like this a lot: set<int> affected_items; while
When writing code using PyQt or PySide, sometimes the equivalent function is available in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.