problem line code not executed

Discussion of the PSoC Creator Integrated Development Environment for PSoC3 & PSoC5 devices.

Moderator: ericb

problem line code not executed

Postby francois65 » Wed Nov 27, 2013 7:01 am

hello

i'm programming with psoc creator 3 on psoc5 LP.

In my code psoc creator unknown some code line !

1 lecture_tab=tab_memorisation[3];
2 if((lecture_tab&ON_OFF_MASK_V1)==ACTIF)
3 {
4 pilote_on_off_V1=ACTIF;
5 }
6 else
7 {
8 pilote_on_off_V1=PAS_ACTIF;
9 }
10
11 lecture_tab=tab_memorisation[3];
12 if((lecture_tab&ON_OFF_MASK_V2)==ACTIF)
13 {
14 pilote_on_off_V2=ACTIF;
15 }
16 else
17 {
18 pilote_on_off_V2=PAS_ACTIF;
19 }


the lines 1 to 9 are correctly executed, but the lines 12 to 17 are ignored and go directly to the line 18.

why?
Last edited by francois65 on Wed Nov 27, 2013 8:11 am, edited 1 time in total.
francois65
Newbie
Newbie
 
Posts: 4
Joined: Tue Jul 21, 2009 12:24 am

Re: problem line code not executed

Postby bobmarlowe » Wed Nov 27, 2013 7:16 am

Why...??? Hmm, my crystal ball is in repair, so you should provide some more information although I already suspect what your bug is. Best would be to upload the complete project here, so that we all can have a look at. Creator -> File -> Create Workspace Bundle (minimal) and the upload the resulting file here.

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: problem line code not executed

Postby francois65 » Wed Nov 27, 2013 7:34 am

i can't give you all project ,but if you need part of program i can.

in the lines which are not executed, in debug mode creator done as this lines don't exist ,i can place break point.

thank you
francois65
Newbie
Newbie
 
Posts: 4
Joined: Tue Jul 21, 2009 12:24 am

Re: problem line code not executed

Postby bobmarlowe » Wed Nov 27, 2013 9:48 am

Please show *ALL* used definitions including types.
I don't know

lecture_tab
tab_memorisation
ON_OFF_MASK_V1
ACTIF
pilote_on_off_V1
pilote_on_off_V2
PAS_ACTIF

On top of this text-windows you have the chance to use tags like "Code". This will preserve indentation when pasting something in between.

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: problem line code not executed

Postby francois65 » Wed Nov 27, 2013 11:55 pm

OK
I send definition including type

just one precision . when I use the debugger ,it skip this lines. I can't place a break point.
Attachments
variable.h
(1.87 KiB) Downloaded 108 times
constante.h
(4.84 KiB) Downloaded 102 times
francois65
Newbie
Newbie
 
Posts: 4
Joined: Tue Jul 21, 2009 12:24 am

Re: problem line code not executed

Postby bobmarlowe » Thu Nov 28, 2013 2:03 am

Yes, as I thought: Your lines have been optimized-out because the boolean expressen can never be true:
you wrote
Code: Select all
#define ON_OFF_MASK_V2   0x02
#define ACTIF            1


12 if((lecture_tab&ON_OFF_MASK_V2)==ACTIF)

which will never ever be true.

I would suggest a principially different approach using boolean algebra and strictly avout comparisions with "==" except for testing numerical values.
In C it is defined (or you may define by yourself)
Code: Select all
#define False 0  // In C-Language the value zero is always false
#define True !False  // This is pure boolean logic


With this in mind you may write
Code: Select all
if(lecture_tab & ON_OFF_MASK_V2)

which will do exactly what you'd like to: When the masked-out bit is set then do...

Again: Strictly avoid comparisions with booleans there are more pitfalls than this one.

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1490
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: problem line code not executed

Postby francois65 » Thu Nov 28, 2013 4:17 am

thank you

I write
Code: Select all
if(lecture_tab & ON_OFF_MASK_V2)


and all it's OK.

thank you very much
francois65
Newbie
Newbie
 
Posts: 4
Joined: Tue Jul 21, 2009 12:24 am


Return to “%s” PSoC Creator (PSoC3 & PSoC5 IDE)

Who is online

Users browsing this forum: No registered users and 1 guest

cron