By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,507 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,507 IT Pros & Developers. It's quick & easy.

how to read confusing execution code under IF condition

P: 1
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!
Nov 10 '08 #1
Share this Question
Share on Google+
2 Replies


Expert 10K+
P: 11,448
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
Nov 10 '08 #2

Expert 100+
P: 2,415
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.
Nov 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.