delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/12/01:03:28

From: Moogla <ngoldber AT lan DOT tjhsst DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: jump to case lable .. in djgpp
Date: Tue, 10 Aug 1999 23:05:27 -0400
Organization: MindSpring Enterprises
Lines: 92
Message-ID: <37B0E877.50A4@lan.tjhsst.edu>
References: <7oqg14$sdd$1 AT garnet DOT nbnet DOT nb DOT ca>
NNTP-Posting-Host: a5.f7.46.7a
Mime-Version: 1.0
X-Server-Date: 11 Aug 1999 03:07:32 GMT
X-Mailer: Mozilla 3.01 (Win95; I)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

guthrie wrote:
> 
> this switch statement says gives the eroors of jump to case label for all
> cases after the first it also says crosses initialization of both of the
> bool variables in case 0:    (bool key_selected  and bool select_done)
> 
> whats going on?
> 
> here's the switch:
> 
> switch(hlite_pos)
>         {
>         case 0:                 // selecting a rotate left key
STOP!

What you are missing is a '{' right here and (scroll down)

> 
>         int new_key;
>         int new_key_shift;
>         bool select_done = false;
>         bool key_selected = false;
>         int enter_key;
> 
>             while(!select_done) file://while a key hasn't been selected or
> esc pressed
>             {
>             // flashing text
>             textout (screen, font , disp1  , 400 , 125, color1);
>             textout (screen, font , "            "  , 400 , 125, color1);
> 
>             delay(30);  file://flash delay time
> 
>             if(!key_selected)   file://if key hasn't been selected
>             {
>                if(keypressed())    // if a key is pressed
>                {
> 
>                new_key = readkey();    file://read key from key buffer
>                new_key_shift = (new_key >> 8);
> 
>                if(new_key_shift == 0x01) file://esc
>                select_done = true;     file://go back to previous menu
> 
>                if(!select_done) file://only if a selection has not yet been
> made
>                {
>                 for(int i = 1 ; i < 13 ; i++) file://find the key in the
> scancode list
>                 {                             // and set it to given
> movement
>                    if(new_key_shift == bkey[i].hex_val)
>                    {
>                    k_rot_left = bkey[i].hex_val;
>                    disp1 = bkey[i].key_disp;
>                    i = 15;    file://stop the for loop
>                    }// end if
>                 }//end for
>                }//end if
>                 key_selected = true;
>                }// end if
>             }// end if
> 
>         if(key_selected)   file://once key has been selected
>         {
>               if(keypressed())   file://wait til key pressed
>               {
>               enter_key = readkey();    file://read the key from the buffer
> 
>                    if(enter_key == 0x1c)     file://the enter key scancode
>                    select_done = true;       file://if enter ..exit the loop
> ..key has been set
>               }// end if
>         } file://end if
> 
>            file://convert scancode and set movement key to new key
> 
>         }//end while
STOP AGAIN!

...you need a '}' right here (for end case 0)

Why? Gcc gets crazy when you declare variables (like all of them in case
0) who can be accessed in other cases (because that's how C cases
work). Since you can jump over case 0, then they won't be declared, and
that's bad.

So put braces around your case statement so all variables are local and
now we have given them a solid scope. Gcc is happy. You are happy.
I am happy. Everyone is happy, happy, happy!

moogla

- Raw text -


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