delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/12/19/14:43:50

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Reply-To: Cygwin List <cygwin AT cygwin DOT com>
Message-Id: <6.2.0.14.0.20041219143737.04a82e30@pop.prospeed.net>
Date: Sun, 19 Dec 2004 14:38:37 -0500
To: Mikael =?iso-8859-1?Q?=C5sberg?= <mikas493 AT student DOT liu DOT se>,
<cygwin AT cygwin DOT com>
From: Larry Hall <lh-no-personal-replies-please AT cygwin DOT com>
Subject: Re: Where did the output go and question regarding return values of getopt_long()
In-Reply-To: <006d01c4e5dd$7e4bda90$0200a8c0@mindcooler>
References: <006d01c4e5dd$7e4bda90$0200a8c0 AT mindcooler>
Mime-Version: 1.0

At 10:14 AM 12/19/2004, you wrote:
>Hello, consider this c++-function:
>
>void
>handle_command_line(int argc,
>                   char* const argv[],
>                   bool& verbose,
>                   vector<string>& numbers)
>{
>  const int id_numbers = 4711;
>  const int id_verbose = 4712;
>  const int id_help = 4713;
>
>  const option long_options[] =
>  {
>     {"numbers", 1, NULL, id_numbers},
>     {"verbose", 0, NULL, id_verbose},
>     {"help", 0, NULL, id_help},
>     {NULL, 0, NULL, 0}
>  };
>
>  const char* const short_options = "";
>
>  int c = 0;
>
>  while((c = getopt_long(
>            argc,
>            argv,
>            short_options,
>            long_options,
>            NULL)) != -1)
>  {
>     switch(c)
>     {
>        cout << "c = " << c << endl; /* Never shown on screen... */
>
>        case id_numbers:
>        {
>           cout << "Calling extract_numbers() with " << optarg << endl;
>
>           extract_numbers(optarg, numbers);
>
>           break;
>        }
>        case id_verbose:
>        {
>           cout << "Setting verbose = true" << endl;
>
>           verbose = true;
>
>           break;
>        }
>        case id_help:
>        {
>           cout << "TODO: Add short description regarding usage here." << endl;
>
>           exit(EXIT_SUCCESS);
>        }
>        /* c seems to equal '?' for missing parameter as well... */
>        case ':':
>        {
>           cerr << "Missing parameter." << endl;
>
>           break;
>        }
>        /* Only triggers for unknown options beginning with -- */
>        case '?':
>        {
>           cerr << "Ignoring unknown option." << endl;
>
>           break;
>        }
>        default:
>        {
>           /* Throw exception? */
>           cerr << "Should not be reached." << endl;
>        }
>     }
>  }
>}
>
>My first question is about the
>cout << "c = " << c << endl;
>inside the switch. I never see this output, why? I tried writing the output to a file as well but that file was empty when the program finished. All other "output-statements" are displayed just fine in this function (and the rest of the program).

Did you look at the warning you get from the line in question?

warning: unreachable code at beginning of switch statement



--
Larry Hall                              http://www.rfk.com
RFK Partners, Inc.                      (508) 893-9779 - RFK Office
838 Washington Street                   (508) 893-9889 - FAX
Holliston, MA 01746                     


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019