View previous topic :: View next topic |
Author |
Message |
Ermes84
Joined: 22 Feb 2019 Posts: 1
|
IF statement anomaly |
Posted: Fri Feb 22, 2019 7:26 am |
|
|
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: 9246 Location: Greensville,Ontario
|
|
Posted: Fri Feb 22, 2019 9:19 am |
|
|
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
|
|
Posted: Fri Feb 22, 2019 9:36 am |
|
|
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: 1358
|
|
Posted: Fri Feb 22, 2019 9:00 pm |
|
|
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
|
|
Posted: Sat Feb 23, 2019 8:20 am |
|
|
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: 19552
|
|
Posted: Sat Feb 23, 2019 8:31 am |
|
|
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... |
|
|
|