CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

[Solved] Disable "May be missing a break" warnings

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

[Solved] Disable "May be missing a break" warnings
PostPosted: Fri Jan 31, 2020 2:01 pm     Reply with quote

Code:
>>> Warning 242 "C:\Program Files (x86)\PICC\Drivers\math.h" Line 1799(10,11): May be missing a break


On some compilers, there is an extension to tell the compiler it's okay to do things like this:

Code:
switch (i)
{
   case 1:
   case 2:
      break;

   case 4:
      // do something
   case 5:
      // then do this
      break;

   default:
      break;
}


CCS has warnings in the math.h file, and under GCC and other compilers you can add a special comment or keyword to tell the compiler it's intentional.

Code:

case 1: // Depending on GCC version, one of these used to work:
   //fall through
   //no break
case 2:
   // stuff
   break;


In an effort to clean up some of our code, I want to eliminate compiler warnings, but since I get some in the CCS-provided header files, I'm not sure what to do there.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?


Last edited by allenhuffman on Tue Feb 04, 2020 8:36 am; edited 4 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 31, 2020 2:20 pm     Reply with quote

Quote:
#ignore_warnings

Syntax:
#ignore_warnings ALL
#IGNORE_WARNINGS NONE
#IGNORE_WARNINGS warnings

Elements:
warnings is one or more warning numbers separated by commas.

Description:
This function will suppress warning messages from the compiler.

ALL indicates no warnings will be generated.

NONE indicates all warnings will be generated. If numbers are listed then
those warnings are suppressed.

Examples:

#ignore_warnings 203
while(TRUE) {
#ignore_warnings NONE
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 03, 2020 11:06 am     Reply with quote

PCM programmer wrote:
#ignore_warnings 203
while(TRUE) {
#ignore_warnings NONE


Fantastic - being able to selectively toggle it around certain code is exactly what I was after. Thank you.

EDIT: Odd. The same test code I built last week that showed warnings in math.h is showing none today. I must have imagined it.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?


Last edited by allenhuffman on Mon Feb 03, 2020 11:32 am; edited 1 time in total
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 03, 2020 11:27 am     Reply with quote

In my case, we had some code where multiple cases would run the same code -- and this took care of those warnings:

Code:
#ignore_warnings 242
         case 'X':
         case 'x':
#ignore_warnings none


I got the 242 warning value from the error display (the help file didn't list numbers, just text/descriptions):

Code:
>>> Warning 242 "(path)\main.c" Line 657(21,22): May be missing a break


(I did ask the programmer why not do 'switch(toupper(key))' and just check uppercase, but he had some situations where lower and upper did different things, and some where they did the same.

But nice to now have less warnings.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Mon Feb 03, 2020 1:06 pm     Reply with quote

Honestly, 'toupper' uses a lot more code than the second switch...
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 04, 2020 8:37 am     Reply with quote

Ttelmah wrote:
Honestly, 'toupper' uses a lot more code than the second switch...


I think it's more of a "Clean Code" approach, removing extra code a human has to deal with. Being exposed to that at my last job was quite enlightening, though it can't apply in every embedded situation (where CPU cycles might be more critical, or RAM/ROM space is limited).
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group