Google Answers Logo
View Question
Q: Finding the definitive answer for ANSI c questions ( Answered 5 out of 5 stars,   0 Comments )
Subject: Finding the definitive answer for ANSI c questions
Category: Computers > Programming
Asked by: borkmark_squil-ga
List Price: $15.00
Posted: 25 Feb 2003 11:28 PST
Expires: 27 Mar 2003 11:28 PST
Question ID: 166997

I'm interested in finding the source of definitive answers for
advanced ANSI c questions. I program in c, and oftentimes wonder how
the compiler must intepret what I write.

An example question is the following:

switch (var)
    case 4:
            /* bla bla bla */
           /* bla bla bla */
    case 8:
          /* bla bla bla */

Question: If the value of 'var' is 8 in the above example, would it
enter the 'default' case or the 'case 8' case (note the order of the

Again, I'm looking for the website(s) or book(s) that would contain
the final answer to such a question. Also, if you can answer the above
specific question itself that would be great, but it's not required.

Subject: Re: Finding the definitive answer for ANSI c questions
Answered By: hammer-ga on 25 Feb 2003 12:01 PST
Rated:5 out of 5 stars
The ANSI standard for the switch statement says the following:
"[#5] The integer promotions are performed on the controlling
       expression.  The constant expression in each case  label  is
       converted   to   the   promoted   type  of  the  controlling
       expression.  If  a  converted  value  matches  that  of  the
       promoted   controlling  expression,  control  jumps  to  the
       statement following the matched case label.   Otherwise,  if
       there  is  a  default  label,  control  jumps to the labeled
       statement.  If no converted case constant expression matches
       and there is no default label, no part of the switch body is

According to this, if var = 8, then case 8 will run. I have confirmed
this with a small sample program.

I found this information in the C ANSI standard. A copy can be found
at the DKUUG web site.


Additional Resources

Lysator University ANSI C Resources

American National Standards Institute

Search Strategy
Google Search Terms:

By the way, for simple questions, writing a small test program is
often the quickest way to get an answer. <grin>

Good luck!

- Hammer
borkmark_squil-ga rated this answer:5 out of 5 stars
The response answered both questions I had, and was very timely
(within a couple of hours). Thanks!

There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy