This is a basic question, but I'm hoping someone can help decipher this line of code for me. I can't find a reference anywhere to what the period in this statement does. I assume by the setup that it is some sort of conditional, but would appreciate any further info. Is it Keil specific? Counter[CounterInstance].Output = FALSE
It's a structure member selection operator. Plain old 'C', not Keil specific. I think you'll have to buy a 'C' book...
Sir, You need to learn C to understand what this does (and further understand that this is NOT a conditional expression, but an assigment). I guess you're a pascal guy or something? That's what I recall conditionals looking like in pascal in a former life. Basically, the variable "Counter" is an array of "structures." In C, to access a member of a specific structure, you use a "." and then the name of the member. So... this statement says that the "Output" member of the "counterinstance-th" element in the array "Counter" is being assigned the value of FALSE; And I suspect that none of that will make any sense unless you buy a C book.
Thanks for the prompt replies, guys. Believe it or not, I was unable to find this syntax in TWO different C books. I suspect it was because I was concentrating on trying to find it in the sections that cover conditionals rather than assignments. I will do some reading up on this operator. Thanks again!
"Believe it or not, I was unable to find this syntax in TWO different C books" The definitive 'C' book must be The C Programming Language by Kernighan & Ritchie (commonly known as "K&R"): http://www.cs.bell-labs.com/cm/cs/cbook/index.html http://www.amazon.co.uk/exec/obidos/ASIN/0131103628/qid=1124807077/sr=1-1/ref=sr_1_10_1/026-5100447-3280432 The dot ("period") operator is actually listed under '.' right at the start of the index of this book - so you'd have no trouble there! "I was concentrating on trying to find it in the sections that cover conditionals" Why? If your 'C' books are so bad that they don't clearly point out the difference between the assignment operator, '=', and equality relational operator, '==', then you should throw them away now! Using '=' when '==' is needed is a classic 'C' programming error! Again, K&R lists '=' and '==' right at the start of the index
In addition to K&R I'd recommend "C - A Reference Manual" by Harbison and Steele. I get the impression that somebody has just plonked a load of code on you and asked you to fix or modify it? If so, good luck, and don't hesitate to post any more questions.
"In C, to access a member of a specific structure, you use a '.' and then the name of the member" Although they're called "records" rather than "structures" in Pascal, the notation is identical - so even a Pascal programmer should understand it!
We started with
Counter[CounterInstance].Output = FALSE
if( something == TRUE )
A comparison of 'C' and Pascal Syntax: http://www.cs.gordon.edu/courses/cs320/handouts/C_C++_Syntax_vs_Pascal.html Note that his comment, "0 = false and 1 = true" is not quite right - see above. Note also that it originated in 1989, so some of his reference to "modern", etc, are now a bit dated.
"if( something == TRUE ) is likely to give unexpected results..." Naturally 'C' provides some fun ways to get round this problem: #define TRUE 1 #define FALSE 0 if(something?1:0 == TRUE) { //Result as expected } or even better: if(!!something == TRUE) { //Result as expected }
Naturally 'C' provides some fun ways to get round this problem: You skipped the most important way: not to create the problem in the first place, so you don't have to work around it:
if(something)
I was unable to find this syntax in TWO different C books That's a symptom of attacking the problem from entirely the wrong direction. You can't seriously expect to understand a completely new language by "finding" individual aspects in a textbook. You have to actually learn the language, and still has to be done by working through a textbook, from cover to cover, not by jumping all over the place with a somewhat involved code example in hand. Once you have got the general picture, you can go back to picking up individual aspects out of the book as you need them, but you absolutely need that general picture first.
Someone did indeed plunk a load of C source code and asked me to do some white box testing of some new revisions. I have much more experience with C++ and Assembly, but minimal C experience. Reading through Dietel and Dietel's "C-How to Program" obviously did not "teach" me the language as it should be taught (with examples, etc), as can be told by how I did not know the answer to this simple question. Thanks again, guys.
"I have much more experience with C++" But the '.', '=', and '==' operators in C++ are identical to those in 'C'!!