/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Using "built-in" functions like strlen()

Username:     
Password:     
             

Forum
  • Index
  •  » circleOS
  •  » Using "built-in" functions like strlen()

# 1   2007-11-03 10:34:03 Using "built-in" functions like strlen()

dalewheat
Member
From: Dallas TX USA
Registered: 2007-10-10
Posts: 43
Website

Using "built-in" functions like strlen()

I prefer centered text on the LCD for legibility, so I wrote a small function to center text for me after I got tired of calculating the offsets in my head:

Code:

void DRAW_DisplayStringCenter ( u8 y, char *s ) {

   u8 x;

   x = ( SCREEN_WIDTH - ( strlen ( s ) * DRAW_GetCharMagniCoeff () * CHAR_WIDTH )) / 2;
   DRAW_DisplayString ( x, y, s, strlen ( s ) );
}

This code works well enough and takes the current 'character magnification coefficient' into consideration as well.  It's not complicated.

I used the strlen() function twice here:  once in calculating the horizontal offset and again to inform the DRAW_DisplayString() function how many characters to display.  A more optimized solution would determine the string length once and store it in a local variable instead of calling the strlen() function twice with the same, unchanged parameter.

As written, this code will build but generates a warning:

Code:

warning: incompatible implicit declaration of built-in function 'strlen'

If I #include the string function header file...:

Code:

#include <string.h>

then the above warning goes away but it replaced with another one:

Code:

warning: passing argument 1 of 'strcmp' make pointer from integer without a case

...complaining of the use of the strcmp() function in the CircleOS version check at the beginning of the application initialization function, Application_Ini(), because the UTIL_GetVersion() function, which is documented as returning a "const char *" is actually returning a "u32" per the circle_api.h include file.

Adding a cast to the function call removes the warning.  I'm not sure how to correct the header file as I am unfamiliar with the technique being used in the function declarations.


Thanks,

Dale Wheat

Offline

 

# 2   2007-11-03 22:09:08 Using "built-in" functions like strlen()

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Using "built-in" functions like strlen()

It's a mistake in the circle_API.h header file.  UTIL_GetVersion()  should return a  "const char"".

Offline

 

  • Index
  •  » circleOS
  •  » Using "built-in" functions like strlen()

Board footer