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 CCS Technical Support

IF statement anomaly

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



Joined: 22 Feb 2019
Posts: 1

View user's profile Send private message

IF statement anomaly
PostPosted: Fri Feb 22, 2019 7:26 am     Reply with quote

Hi all,

I would like to address a problem I encountered regarding the if statement.
I use PCWHD Compiler ver 5.048 and PIC18F27J13

This code does not work ():

Code:


do_ACKLOD = FALSE;

if (do_ACKLOD)
    BootLoaderPutc(ACKLOD);



The BootLoaderPutc function is executed even if the condition is false.

Instead this works:

Code:


do_ACKLOD = FALSE;

if (do_ACKLOD)
{
    BootLoaderPutc(ACKLOD);
}



This code is a piece of code from the CCS bootloader.
Can someone explain to me why?
Thank you.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 22, 2019 9:19 am     Reply with quote

might be 'white space' after the if(...) ?

if(xxx) ...hidden white space or tab...


I have to admit I use a LOT of brackets, braces, parentheseses...on the idea if I can figure it ou, so can the compiler !

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 22, 2019 9:36 am     Reply with quote

Did you type that code in to your post, or did you copy-and-paste it in
directly from your actual program ?
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Fri Feb 22, 2019 9:00 pm     Reply with quote

If BootLoaderPutc is a macro, then it could also be the cause of your problem depending on how the macro is defined.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 23, 2019 8:20 am     Reply with quote

Hi Jeremiah,
Yes it's a macro. It's in loader.c, which is a CCS bootloader driver file.

Using that knowledge, I made a test program. I installed vs. 5.048 and
ran the following program in MPLAB vs. 8.92 simulator. It works.
I tested it with both definitions of BootLoaderPutc(), and tested each one
with do_ACKLOD set to TRUE/FALSE.
The results are:
Quote:

Start: A End
Start: End

That's correct. So I don't see a problem. The original poster needs to
give more information.

Test program:
Code:

#include <18F27J13.h>
#fuses HS, NOWDT
#use delay(clock=20M)
#use rs232(baud=9600, UART1, ERRORS)
//#use rs232(baud=9600, UART1, ERRORS, stream=BOOTLOADER_STREAM)

#define BootLoaderPutc(c)    putc(c)
//#define BootLoaderPutc(c)    fputc(c, BOOTLOADER_STREAM)

int1  do_ACKLOD;

#define ACKLOD 'A'  // was 0x06


//======================================
void main()
{                                                                     
do_ACKLOD = TRUE;

printf("Start: ");

if (do_ACKLOD)
    BootLoaderPutc(ACKLOD);


printf("  End \r");

while(TRUE);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Sat Feb 23, 2019 8:31 am     Reply with quote

Yes. My 'guess' would be that the poster has re-defined the macro, and
has got more than one statement in the macro, not realising the
bracketing needed to make this work. Hence it doesn't behave as expected...
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