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

  • Home
  • SEARCH
  • 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 8568011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:00:43+00:00 2026-06-11T18:00:43+00:00

Possible Duplicate: Why Switch/Case and not If/Else If? I would like to understand how

  • 0

Possible Duplicate:
Why Switch/Case and not If/Else If?

I would like to understand how a switch() case: statement in C
is translated by the compiler into assembler opcodes.

Specifically, i’m interested in understanding the difference
with a serie of if then else branches.

Performance comparison is the main topic.

A few words on vocabulary :
i’m familiar with assembler main concepts, having coded in assembler a long time ago for simpler systems, But certainly do not now anything about x86 assembler semantic.
So a direct assembler output will not be useful.
Pseudo-code is much prefered.

  • 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-11T18:00:44+00:00Added an answer on June 11, 2026 at 6:00 pm

    The compiler can decide to implement it as the equivalent series of if/else if statements, or it may decide to optimize it using a branch table. This depends on several parameters such as the number of branches and the size of minimum range that includes all values you check against.

    Update: I remember reading somewhere that typically compilers do not bother to create a branch table unless there are at least 4 switch cases or more; Stephane Rouberol’s informative comment below specifically documents how this threshold can be configured for GCC.

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

Sidebar

Related Questions

Possible Duplicate: is “else if” faster than “switch() case” ? I've encountered a lot
Possible Duplicate: ‘break’ statement when using curly braces in switch-case While merging a package
Possible Duplicate: How to switch an Application between Themed and not Themed at run-time?
Possible Duplicate: Is it safe to assume strict comparison in a Javascript switch statement?
Possible Duplicate: Why can't variables be declared in a switch statement? How can a
Possible Duplicate: Switch Case on type of object (C#) I have a method signature
Possible Duplicates: is “else if” faster than “switch() case” ? What is the relative
Possible Duplicates: Is "else if" faster than "switch() case"? What is the relative performance
Possible Duplicate: Switch statement fallthrough in C#? The following code is illegal in C#
Possible Duplicate: Dynamic LINQ OrderBy switch (sort) { case Title: queryResults = queryResults.OrderBy(r =>

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.