Helpful ReplyHot!errors and warnings

Page: 12 > Showing page 1 of 2
Author
Andy_Taiwanese
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2014/12/19 02:59:38
  • Location: 0
  • Status: offline
2017/10/12 23:19:44 (permalink)
0

errors and warnings

Hi, there.
I'm building the program and faced some problems. I've checked the XC8 manual. There are the rest I don't know how to fix it.
IDE: X v3.60
PIC: 16F1824
compiler: XC8 v1.42
 
1.
I2C.c:6: error: (208) operands of "==" not same type

I2C.c:
bit I2C_Write(unsigned char address, unsigned char command, unsigned char value)
{
    if(I2C_Start == Failure) return Failure; // THIS LINE GOES WRONG
    
    if(I2C_SendAddress(address) == Failure) return Failure; // Write slave
    
    if(I2C_SendAddress(command) == Failure) return Failure; // Register address
    
    if(I2C_SendAddress(value) == Failure) return Failure; // write value
    
    I2C_Stop();
    
    return Success;
}

bit I2C_Start(void)
{
    SSP1BUF =0x00;
    SSP1CONbits.SSPEN=1; // SSP module on
    
    while ( ( SSPCON2 & 0x1F ) || ( R_nW ) ); // Idle?
    
    SSP1CON2bits.SEN=1; // Initial start condition
    while (SSP1CON2bits.SEN != 0);
    if (PIR2bits.BCL1IF == 1){
        I2C_Stop();
        flag.BCL = 1;
        return Failure;
    }
    while(PIR1bits.SSP1IF != 1);
    PIR1bits.SSP1IF=0;
    return Success;
}

These are definitions:
#define Failure 1
#define Success 0

I'm sure of the fact that the operands of the "==" are the same type.
 
 
2.
I2C.c:27: warning: (373) implicit signed to unsigned conversion

if(I2C_SendAddress(address+1) == Failure) return Failure;    //This line goes wrong

This line seems same to the previous one, but different warning happened.
I don't see the implicit conversion problem.
 
3.
difficult.c:46: warning: (374) missing basic type; int assumed
difficult.c:46: error: (984) type redeclared
difficult.c:46: error: (1098) conflicting declarations for variable "OTHER_FLAGbits" (difficult.c:45)

global variable in main.c:
OTHER_FLAG OTHER_FLAGbits;
OTHER_FLAGbits.first_interrupt = 0    //374, 984 and 1098 all goes for this line;

header.h:
typedef struct{
    volatile unsigned first_interrupt :1;
    unsigned UT_EVT :1;
    unsigned OT_EVT :1;
    unsigned OV_EVT :1;
    unsigned VLPF_EVT :1;
    unsigned OC0_EVT :1;
    unsigned CHG_STA :1;
    unsigned DHG_STA :1;
}OTHER_FLAG;

I only declare OTHER_FLAG once in the header file.
I've tried many times to debug with it. Please give me some advice, thank you
post edited by Andy_Taiwanese - 2017/10/12 23:45:38
#1
jtemples
Super Member
  • Total Posts : 10199
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: errors and warnings 2017/10/12 23:44:35 (permalink)
+2 (2)
    if(I2C_Start == Failure) return Failure; // THIS LINE GOES WRONG

 
I'm guessing I2C_Start is a function, and you've left the () off.
#2
NKurzman
A Guy on the Net
  • Total Posts : 14848
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: errors and warnings 2017/10/12 23:44:39 (permalink)
+1 (1)
if(I2C_Start() == Failure)
#3
Andy_Taiwanese
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2014/12/19 02:59:38
  • Location: 0
  • Status: offline
Re: errors and warnings 2017/10/12 23:55:17 (permalink)
0
To jtemples and NKurzman:
Thank you!!
#4
Andy_Taiwanese
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2014/12/19 02:59:38
  • Location: 0
  • Status: offline
Re: errors and warnings 2017/10/13 01:29:37 (permalink)
0
m....I found the solution of problem 2.
 
use
if(I2C_SendAddress(++address) == Failure) return Failure; // Read slave

rather than
if(I2C_SendAddress(address+1) == Failure) return Failure; // Read slave

 
But, why the second one doesn't work? I remember that standard C accepts statement as the parameter.
post edited by Andy_Taiwanese - 2017/10/13 01:48:32
#5
qhb
Superb Member
  • Total Posts : 5824
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: errors and warnings 2017/10/13 01:54:56 (permalink) ☄ Helpfulby Andy_Taiwanese 2017/10/15 19:17:40
+1 (1)
What is the "type" of address, and the "type" of Failure?
The first form actually changes the value of address, and passes a value of the same type as address.
The second form does not change address, and will pass an integer to the function.
Whether it is signed or unsigned depends upon what type address is.
 
#6
DarioG
Scheisse Menschen
  • Total Posts : 52446
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: hi there
  • Status: online
Flagged as Spam (1)
Re: errors and warnings 2017/10/13 01:58:49 (permalink)
0
address | 1
is in my opinion the best form.
#7
Andy_Taiwanese
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2014/12/19 02:59:38
  • Location: 0
  • Status: offline
Re: errors and warnings 2017/10/13 02:23:36 (permalink)
0
qhb
What is the "type" of address, and the "type" of Failure?
The first form actually changes the value of address, and passes a value of the same type as address.
The second form does not change address, and will pass an integer to the function.
Whether it is signed or unsigned depends upon what type address is.

The type of address is unsigned char; I don't know the type of Failure, I remember compiler will give an appropriate type for it in #define condition.
 
What is "first form"? What is "second form"
 
Sorry, I really don't know what you're saying :(
#8
Andy_Taiwanese
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2014/12/19 02:59:38
  • Location: 0
  • Status: offline
Re: errors and warnings 2017/10/13 02:28:55 (permalink)
+1 (1)
DarioG
address | 1
is in my opinion the best form.


Thank you, but why address+1 doesn't work? It does work in gcc compiler which I tried.
#9
DarioG
Scheisse Menschen
  • Total Posts : 52446
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: hi there
  • Status: online
Re: errors and warnings 2017/10/13 02:40:49 (permalink) ☄ Helpfulby Andy_Taiwanese 2017/10/15 19:14:30
0
It would fail if address is an odd value... but I suppose this is not your case. So am not sure..
#10
1and0
Access is Denied
  • Total Posts : 6964
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: errors and warnings 2017/10/13 02:53:30 (permalink) ☄ Helpfulby Andy_Taiwanese 2017/10/17 01:33:42
+1 (1)
Andy_Taiwanese
 
The type of address is unsigned char; I don't know the type of Failure, I remember compiler will give an appropriate type for it in #define condition.
 
What is "first form"? What is "second form"
 
Sorry, I really don't know what you're saying :(

The "first" form is
if(I2C_SendAddress(++address) == Failure) return Failure; // Read slave

and the "second" form is
if(I2C_SendAddress(address+1) == Failure) return Failure; // Read slave

That said, (++address) is unsigned char while (address+1) is a signed int.
#11
qhb
Superb Member
  • Total Posts : 5824
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: errors and warnings 2017/10/13 03:22:40 (permalink) ☄ Helpfulby Andy_Taiwanese 2017/10/15 19:14:11
+1 (1)
Andy_Taiwanese
The type of address is unsigned char;

In that case, the type of ++address is also unsigned char,
but the type of address+1 is unsigned int.
Andy_Taiwanese
What is "first form"? What is "second form"


The "first form" is from your first expression
if(I2C_SendAddress(++address) == Failure) return Failure; // Read slave

i.e. "++address"


the "second form" is from your second expression
if(I2C_SendAddress(address+1) == Failure) return Failure; // Read slave

i.e. "address+1"
 
#12
1and0
Access is Denied
  • Total Posts : 6964
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: errors and warnings 2017/10/13 03:44:38 (permalink)
+1 (1)
qhb
 
but the type of address+1 is unsigned int.

Shouldn't that be signed?
#13
qhb
Superb Member
  • Total Posts : 5824
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: errors and warnings 2017/10/13 04:10:38 (permalink) ☄ Helpfulby Andy_Taiwanese 2017/10/15 19:14:01
+3 (3)
1and0
qhb
but the type of address+1 is unsigned int.

Shouldn't that be signed?

You're right. That's one rule I often don't get right in my head.
When promoting, it always goes to signed int unless it is too big to be signed int, but small enough to be a unsigned int.
#14
Andy_Taiwanese
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2014/12/19 02:59:38
  • Location: 0
  • Status: offline
Re: errors and warnings 2017/10/15 19:17:23 (permalink)
+1 (1)
To all:
Thank you all, all your reply makes me a better programmer.
I found the source of problem 3.
I missed the right brackets "}" of the main function.
#15
Andy_Taiwanese
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2014/12/19 02:59:38
  • Location: 0
  • Status: offline
Re: errors and warnings 2017/10/18 03:32:14 (permalink)
0
Hi, there! I'm proceeding this project and face other problems.
 
The first category is relatively easier(picture 1).
error 192: Why parser can't find the source of these name? parser does it for other names.
I may add the struct name in front of it, just want to know the reason why.
 
Secondly question, in this code:
unsigned char safety_event = 0;
 
if( I2C_Read(OZ8920, SAFETY_EVENT_REGISTER, &safety_event, &safety_event, 1) == SUCCESS ){
    ALARM_FLAGbits.SCN_EVT = safety_event & 0b10000000; // warning 373
}
else OTHER_FLAGbits.cmmu_fail = 1;

goes with:
warning 373: implicit signed to unsigned conversion.

I tried changing it to:
    if( I2C_Read(OZ8920, SAFETY_EVENT_REGISTER, safety_event, safety_event, 1) == SUCCESS ){
        ALARM_FLAGbits.SCN_EVT =
        safety_event & 0b10000000; // still warning 373
    }

then I changed it to:
    if( I2C_Read(OZ8920, SAFETY_EVENT_REGISTER, safety_event, safety_event, 1) == SUCCESS ){
        /*ALARM_FLAGbits.SCN_EVT = */
        safety_event & 0b10000000; // no warning
    }

The warning disappears.
I originally thought it's the bitwise operator problem, but it turns out like = operator problem.
How do I deal with this situation? I want to save 1-bit wide information from unsigned char safety_event.
 
Third question, in this same code:
unsigned char safety_event = 0;
 
if( I2C_Read(OZ8920, SAFETY_EVENT_REGISTER, &safety_event, &safety_event, 1) == SUCCESS ){ //warning 359
    ALARM_FLAGbits.SCN_EVT = safety_event & 0b10000000; // warning 373
}
else OTHER_FLAGbits.cmmu_fail = 1;

goes with:
difficult.c:107: warning: (359) illegal conversion between pointer types pointer to unsigned char -> pointer to pointer to const unsigned char

This is prototype:
bit I2C_Read(unsigned char address, const unsigned char command, const unsigned char *array_low_ptr[], const unsigned char *array_high_ptr[], const unsigned char length);

 
I tired to debug and didn't work. May someone give me a hint? Thank you!
 
 
 
post edited by Andy_Taiwanese - 2017/10/18 18:43:05

Attached Image(s)

#16
1and0
Access is Denied
  • Total Posts : 6964
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: errors and warnings 2017/10/18 04:56:21 (permalink)
+1 (1)
Andy_Taiwanese
The first category is relatively easier(picture 1).
error 192: Why parser can't find the source of these name? parser does it for other names.
I may add the struct name in front of it, just want to know the reason why.
 
Add the struct name, because the bit names are member of a struct.
 

Secondly question, in this code:
unsigned char safety_event = 0;
 
if( I2C_Read(OZ8920, SAFETY_EVENT_REGISTER, &safety_event, &safety_event, 1) == SUCCESS ){
    ALARM_FLAGbits.SCN_EVT = safety_event & 0b10000000; // warning 373
}
else OTHER_FLAGbits.cmmu_fail = 1;

goes with:
warning 373: implicit signed to unsigned conversion.


Try making the constant an unsigned value.
 

I tried changing it to:
    if( I2C_Read(OZ8920, SAFETY_EVENT_REGISTER, safety_event, safety_event, 1) == SUCCESS ){
        ALARM_FLAGbits.SCN_EVT =
        safety_event & 0b10000000; // still warning 373
    }


Of course it is the same, because C does not care much about write space.
 

then I changed it to:
    if( I2C_Read(OZ8920, SAFETY_EVENT_REGISTER, safety_event, safety_event, 1) == SUCCESS ){
        /*ALARM_FLAGbits.SCN_EVT = */
        safety_event & 0b10000000; // no warning
    }

The warning disappears.

No warning, because it's most likely being optimize out for doing nothing.
 

I originally thought it's the bitwise operator problem, but it turns out like = operator problem.
How do I deal with this situation? I want to save 1-bit wide information from unsigned char safety_event.

Post the definition of ALARM_FLAGbits.  Bit fields are unsigned in XC8, so I don't think it's the = operator problem.
 

Third question, in this same code:
unsigned char safety_event = 0;
 
if( I2C_Read(OZ8920, SAFETY_EVENT_REGISTER, &safety_event, &safety_event, 1) == SUCCESS ){ //warning 359
    ALARM_FLAGbits.SCN_EVT = safety_event & 0b10000000; // warning 373
}
else OTHER_FLAGbits.cmmu_fail = 1;

goes with:
difficult.c:107: warning: (359) illegal conversion between pointer types pointer to unsigned char -> pointer to pointer to const unsigned char

This is prototype:
bit I2C_Read(unsigned char address, const unsigned char command, const unsigned char *array_low_ptr[], const unsigned char *array_high_ptr[], const unsigned char length);


*array_xxx_ptr[] is a pointer to pointer, and only a pointer is passed to it.
 

Fourth question, in this code:
    unsigned char safety_status = 0;
    
    if( I2C_Read(OZ8920, SAFETY_STATUS_REGISTER, safety_status, safety_status, 1) == SUCCESS ){ //warning 357
        ALARM_FLAGbits.UT_STA = safety_status & 0b00001000; //warning 373
        ALARM_FLAGbits.OT_STA = safety_status & 0b00000100; //warning 373
        ALARM_FLAGbits.UV_STA = safety_status & 0b00000010; //warning 373
        ALARM_FLAGbits.OV_STA = safety_status & 0b00000001; //warning 373
    }
    else OTHER_FLAGbits.cmmu_fail = 1;

goes with:
difficult.c:143: warning: (357) illegal conversion of integer to pointer

This function I2C_Read is the same as previous one, I don't know why warning 357 occurs here and warning 359 doesn't.

Again, *array_xxx_ptr[] is a pointe to pointer, and only an integer is passed to it.
 
 
I tired to debug and didn't work. May someone give me a hint? Thank you!

Keep trying. ;)
 
#17
Andy_Taiwanese
Super Member
  • Total Posts : 355
  • Reward points : 0
  • Joined: 2014/12/19 02:59:38
  • Location: 0
  • Status: offline
Re: errors and warnings 2017/10/18 22:56:37 (permalink)
0
To 1and0:
I was debugging last night til 8 p.m. Here is my feedback.
 
The member which occur error 192 have one thing in common: They are all in the union. For example:
typedef union {
    struct {
        unsigned ADPREF0 :1;
        unsigned ADPREF1 :1;
        unsigned ADNREF :1;
        unsigned :1;
        unsigned ADCS0 :1;
        unsigned ADCS1 :1;
        unsigned ADCS2 :1;
        unsigned ADFM :1;
    };
    struct {
        unsigned ADPREF :2;
        unsigned :2;
        unsigned ADCS :3;
    };
} ADCON1bits_t;
extern volatile ADCON1bits_t ADCON1bits @ 0x09E;

    ADCS = 0b100; //this line goes error before add the struct name
    ADPREF = 0b00; //this line goes error before add the struct name

I'm guessing that the compiler doesn't recognize the second group member of struct if there is no struct name in front of member. 
 
In this line:
ALARM_FLAGbits.SCN_EVT = (safety_event & 0b10000000);

The constant 0b10000000 is unsigned int as per:
1. XC8 user guide
All constants can be expressed in (unsigned) binary, octal, decimal or hexadecimal, as per normal C syntax.

2. http://en.cppreference.co...ion#Integral_promotion
arithmetic operators do not accept types smaller than int as arguments, and integral promotions are automatically applied after lvalue-to-rvalue conversion

then as per website again:
unsigned char or unsigned short can be converted to int if it can hold its entire value range, and unsigned int otherwise;

That is, safety_event turns out to be signed int from unsigned char. During the operator &, 0b1000000 turns out to be signed int from unsigned int.
Come back to strcut ALARM_FLAGbit, the member SCN_EVT is defined as unsigned int.
Therefore, during the operator =, compiler warns user that something could go wrong from signed int to unsigned int.
 
 
post edited by Andy_Taiwanese - 2017/10/18 23:00:51
#18
1and0
Access is Denied
  • Total Posts : 6964
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: errors and warnings 2017/10/19 01:47:45 (permalink)
0
Andy_Taiwanese
I'm guessing that the compiler doesn't recognize the second group member of struct if there is no struct name in front of member. 

If you take a look to the header file for your PIC device, you will find that the single-bit members of the first struct are defined as individual bit definitions, and notice these bit definitions are being deprecated.  There are no bit definitions for the multiple-bit members of the second struct in the header file.  So, I'd suggest you to use the struct_name.member_name form.
 

In this line:
ALARM_FLAGbits.SCN_EVT = (safety_event & 0b10000000);

The constant 0b10000000 is unsigned int as per:

The constant 0b10000000 is _not_ an unsigned int, it is a signed int. Like I said in my previous post, make that constant an unsigned value. To make a constant (literal) unsigned, append a 'u' or 'U' to it. That is, do this
ALARM_FLAGbits.SCN_EVT = (safety_event & 0b10000000u);

and the & operation will be carried out using unsigned int, which will make that warning disappear.
 
 
post edited by 1and0 - 2017/10/19 10:55:26
#19
1and0
Access is Denied
  • Total Posts : 6964
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: errors and warnings 2017/10/19 02:58:44 (permalink)
0
Andy_Taiwanese
ALARM_FLAGbits.SCN_EVT = (safety_event & 0b10000000);

ALARM_FLAGbits.UT_STA = safety_status & 0b00001000; //warning 373
ALARM_FLAGbits.OT_STA = safety_status & 0b00000100; //warning 373
ALARM_FLAGbits.UV_STA = safety_status & 0b00000010; //warning 373
ALARM_FLAGbits.OV_STA = safety_status & 0b00000001; //warning 373

Come back to strcut ALARM_FLAGbit, the member SCN_EVT is defined as unsigned int.

You did not post the definition of ALARM_FLAGbit, even though I asked you to. So I'll assume its members are in fact single-bit bitfields and not 16-bit unsigned int. If that is the case, you will have to change the result of those & operations to either 1 or 0, such as
ALARM_FLAGbits.SCN_EVT = (unsigned) !!(safety_event & 0b10000000);

#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2017 APG vNext Commercial Version 4.5