Connecting Tech Pros Worldwide Forums | Help | Site Map

how to read confusing execution code under IF condition

Newbie
 
Join Date: Nov 2008
Posts: 1
#1: Nov 10 '08
Hi - I'm completely new to C and trying to read some code that doesn't make sense to me. For proprietary reasons I can't display the code here but I'll describe it...and list part of it in a generic form below. I know the basics about IF conditions and have read plenty of them without difficulty but this one is really confusing me.

There is a long, complicated IF condition (1 AND and 2 ORS, with 2 parts to each OR and 2 NOTs!), then a list of code to execute if the IF condition is true, under it.

The execution code looks like this:

output = variable x
variable y = output
variable z [0] = output
variable z [1] = variable [0]

I am very confused. This is part of a continuous simulation block and variables x and y are different inputs to the block, which cannot possibly be the same and (when I tested it) are not forced to be equal to the same value, yet both are said to be equal to the output, which can be only one value. The block runs without glitches so I don't think it's an error in the code. Could someone please explain to me how to read this code? It doesn't make any sense to me but it must be just something I don't know about IF conditions or ignorance of some sort. I'm wondering if the first line is executed during the first time step in the simulation, then the next line during the next time step,or something...

Also, the last 2 lines above...what does this mean? I know about arrays and assume that this has to do with values at different time steps...value 0 is defined at one step, then value 1 is defined at the next step, etc. but I don't get what this code is saying.

Any help would be much appreciated. Thank you so much!
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Nov 10 '08

re: how to read confusing execution code under IF condition


Better show the actual expression because I don't understand anything from your
description. Feel free to change variable names at will as long as the semantics
of your posted expression are the same as the one you're looking at.

kind regards,

Jos
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 830
#3: Nov 10 '08

re: how to read confusing execution code under IF condition


Please also provide the declarations for the variables. For example, perhaps "output" is a pointer to a memory-mapped input port. If so, then you might get a different value each time you read it.

Another issue is to understand what it means in your application domain to take this branch of the if-statement. Perhaps that complicated boolean expression amounts to a corner case where it is necessary to initialize the simulation variables.
Reply