Keil™, An ARM® Company

Technical Support

C166: ERROR C102 (DIFFERENT CONST/VOLATILE...) USING SBIT


Information in this article applies to:

  • C166 Version 4.27

SYMPTOMS

I receive the following error message:

*** ERROR C102 IN LINE 4 OF .\MAIN.C: 'mybit0': different const/volatile qualifiers

when I try to declare an sbit as an external variable. For example, my MAIN.H header file is:

extern bit mybit0; /* bit 0 of ibase */

and my MAIN.C file is:

#include "main.h"

int bdata ibase;          /* Bit-addressable int */
sbit mybit0 = ibase ^ 0;  /* bit 0 of ibase */

void main (void)
{
}

Why am I getting this error message?

CAUSE

This error message is generated because an sbit is not exactly the same variable type as a bit.

RESOLUTION

To resolve this problem, you may declare the bit using the volatile attribute as shown below.

extern volatile bit mybit0; /* bit 0 of ibase */

Another solution is to declare the external bit so that it is not defined at the same time as the sfr. The easiest way to do this is with a #define. For example:

MAIN.H

#ifndef SBITS
extern bit mybit0;         /* Bit 0 of ibase */
#endif

MAIN.C

#define SBITS
#include "main.h"

int bdata ibase;          /* Bit-addressable int */
sbit mybit0 = ibase^0;

void main (void)
{
mybit0 = 0;
}

OTHER.C

#include "main.h"

void myfunc (void)
{
mybit0 = 1;
}

Last Reviewed: Friday, June 25, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure