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 6728099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:07:43+00:00 2026-05-26T10:07:43+00:00

What do I do with this switch-case statement in C ? #if defined MY_CONST

  • 0

What do I do with this switch-case statement in C?

#if defined MY_CONST && define RUN_TEST
    case TX_ERROR:
        //code here
        break;
    case RX_ERROR:
        //other code here
        break;
#endif

I’m coding in an existing project, and I see the above lines in an included header file (in the file I’m working on). No mention of a “switch” anywhere else in the header file!

I’ve never seen this before! How can these be case switches without the switching? Since this must be possible, how can I use these cases in a switch statement in my main file?

EDIT: I can’t post the actual file (code base under licence?), but here’s a stripped version:

#if defined _CONFIG
    #define MY_CONST
    #define MY_INIT
    #define RUN_TEST

    static void fnInit(void);
    static void fnGo(void);
#endif

#if defined MY_CONST && define RUN_TEST
    case TX_ERROR:
        //code here
        break;
    case RX_ERROR:
        //other code here
        break;
#endif

#if defined MY_INIT && defined MY_CONST
static void fnInit(void)
{
    //code
}

static void fnGo(void)
{
    //code
}
#endif
  • 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-05-26T10:07:44+00:00Added an answer on May 26, 2026 at 10:07 am

    Make sure that MY_CONST is never defined!

    If what you quote is accurate, then you’d have to include the header in the scope of a switch statement for the result with MY_CONST defined to make any sense. If it is not embedded in a macro, then it is basically an accident waiting to happen.


    With the revised content, make sure that you never have both MY_CONST and RUN_TEST defined. There is no way for the header to be used sanely if they are — not even if you are using GCC and have nested functions enabled.

    Fundamentally, that fragment is a bug in the header.

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

Sidebar

Related Questions

I have kept hearing this statement. Switch..Case is Evil for code maintenance, but it
I have a switch statement similar to this one: switch (number) { case 1:
I have some code that looks like this: someFunc(value) { switch(value){ case 1: case
Is this code possible? switch (rule) { case 'email' || 'valid_email': valid = this.validate_email(field);
How can I make this work? switch(property.PropertyType){ case typeof(Boolean): //doStuff break; case typeof(String): //doOtherStuff
I'm writing some code that looks like this: while(true) { switch(msg->state) { case MSGTYPE:
I'm trying to implement a switch case statement like this: switch (active.attr('class')){ case video:
I have a really long winded switch case statement like this switch(x){ case a:
I have this #define statement in legacy code I'm inspecting in C . #define
I have a switch case like this switch($filesize_in_bytes){ case 10Mb <= $filesize_in_bytes <= 100Mb:

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.