Shop OBEX P1 Docs P2 Docs Learn Events
FlexProp Compiler Warnings — Parallax Forums

FlexProp Compiler Warnings

Hi @ersmith,

I'm using the FlexProp GUI screen to compile a C program. It gave me several warnings when it came upon some functions. Here's a very small snippet from the code to demonstrate the point:

#define Yes 1
#define No  0

#define ConPort   0
#define CduPort   3

char ConTxDStr[128];  
char CduTxDStr[128];
char ConTxDRdy;
char CduTxDRdy;

void PrintOut(unsigned char Display,char *format,...)
{
 static char ConCduStr[256];    
 va_list ptr;
 va_start(ptr,format);
 vsprintf(ConCduStr,format,ptr);
 va_end(ptr);
 if(strlen(ConCduStr) > 120) return;
 switch(Display)
  {
   case ConPort: strcpy(ConTxDStr,ConCduStr);
                 ConTxDRdy=No;
                 break;
   case CduPort: strcpy(CduTxDStr,ConCduStr);
                 CduTxDRdy=No;
                 break;
   default:      break;
  }
}

void PageSend(unsigned char Display)
{
 PrintOut(Display,"%c",0x1d);
}

This particular warning was in reference to the PageSend() function:

warning: parameter passing discards const attribute from pointer

There are several other functions in addition to PageSend() that got similar warnings.

Keep in mind that the program compiled fine and executed flawlessly, so despite the warnings the various functions worked exactly as expected.

So, I consider these warnings to be informative rather than fatalistic, but I was wondering if there is a way to disable them, or is there a way to adjust the warning outputs based upon their severity?

Comments

  • The easiest way to disable these warnings is to use "const char *" for any parameters that are likely to get literal strings passed to them (like the "format" parameter of PrintOut). The warninig is there because if the function does happen to modify a literal string, either directly or indirectly, that change will affect all uses of the string in the future.

  • Dave HeinDave Hein Posts: 6,347
    edited 2021-07-09 22:58

    Or you could cast the string "%c" to unsigned char *. So your call to PrintOut would be PrintOut(Display, (unsigned char *)"%c",0x1d). You probably don't need to use "unsigned char" in your declarations. I don't see where you need the characters to be unsigned in the way you use them. "char" should be sufficient.

  • @"Dave Hein" said:
    Or you could cast the string "%c" to unsigned char *. So your call to PrintOut would be PrintOut(Display, (unsigned char *)"%c",0x1d). You probably don't need to use "unsigned char" in your declarations. I don't see where you need the characters to be unsigned in the way you use them. "char" should be sufficient.

    Your suggestion worked perfectly! Thanks. And I switched to (char *) instead of (unsigned char *).

    I guess it depends upon the compiler and how strict they are going to enforce the rules.

    The Catalina compiler didn't care about any of this and compiled the code without any warnings.

    These warnings from FlexProp will prompt me to be more careful in coding going forth (no pun intended)...

Sign In or Register to comment.