Thread: function call as a 'case' arguement

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    28

    function call as a 'case' arguement

    is it possible to use a function call as a case argument in a switch statement?

    Ex.

    switch (ch) {
    case isdigit(ch): /* runtime error 'not a constant' */
    state = FRACTIONAL;
    case ' ':
    return (2);
    case 'E':
    state = EXPONENT;
    case 'e':
    state = EXPONENT;
    case 'F':
    state = FLOAT;
    default:
    return(0);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > case isdigit(ch): /* runtime error 'not a constant' */
    And that's what it means

    case labels are integer compile time constants

    You could do
    case 0:
    case 1:
    case 2:
    case 3:
    ..
    case 9:
    state = FRACTIONAL;
    break;

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    28

    thanks for yor help

    That works. Thanks.
    rc7j

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM