View previous topic :: View next topic |
Author |
Message |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
CCS PCH C Compiler, v5.059 SOLVED |
Posted: Mon Jun 13, 2016 10:13 pm |
|
|
1. Just for information
I am compiling my files compiled before with v5.056 Demo with the new compiler above
Two of them using PIC16F1847 giving an error and written "CONTACT CCS..."
I am comparing the .hex files v5.056 & v5.059 and they are similar.
Both working when loaded to the controller.
Somebody had this problem?
I wrote an email to CCS at June 7 about the issue, will update when I will get answer.
2.
Without followed by {}
My question is if the compiler should give an "ERROR" or "WARNING"?
Best wishes
Joe
Last edited by gjs_rsdi on Mon Jul 11, 2016 7:21 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Tue Jun 14, 2016 12:08 am |
|
|
if(data==0)
This is 'general C'. Any logic test, or loop instruction (while, if, do, for etc..), executes the following statement. If you want it to execute more, then you combine multiple statements into a code block, by using the {} brackets, then the whole block is executed instead.
The general syntax from K&R, for 'if', is:
Code: |
if (expression)
statement1;
else
statement2;
|
"One and only one of the two statements associated with an if-else is performed. If the expression is true, statement1 is executed, if not, statement2 is executed. Each statement can be a single statement, or several in braces. The 'else' and it's statement are optional.
So, without the brackets, it will be the following code line that gets executed. |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Tue Jun 14, 2016 12:55 am |
|
|
Thank you Ttelmah
My knowledge in C is limited, I was thinking that must use {}
Best wishes
Joe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Tue Jun 14, 2016 1:03 am |
|
|
Because this can make it hard to really 'see' what code is doing, this is why I like to be really 'forceful' in using indents. So:
Code: |
if (something)
statement;
other code;
if (something else)
{
statement;
another statement;
} //if
yet more code;
|
This way, glancing down the code, you can see what is meant to be being executed for each logic test or loop, by the indentations. Also, given that the IDE (and most other C editors), allow you to jump to the matching bracket, you can simply test that the brackets at each end of a block, have exactly the same indent. If they don't, you know you have missed something. Helps to simplify keeping things sorted. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Tue Jun 14, 2016 6:21 am |
|
|
Another trick that I started doing years ago is that whenever I start an if { } or an else { } or any other type of block, I always type both the opening and closing brace first. When I first started coding I would only type the opening brace, then my code, then the closing brace. Quickly got confusing when I'd insert nested conditional blocks. |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Tue Jun 14, 2016 6:34 am |
|
|
Thanks again Ttelmah
I made a small test:
Code: | int data=1;
if(data==0)
data=1;
data=0; |
Acts exactly as:
Code: | int data=1;
if(data==0)
{
data=1;
}
data=0; |
Everything clear
Best wishes
Joe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Tue Jun 14, 2016 6:54 am |
|
|
However, clearer done as:
Code: |
int data=1;
if(data==0)
data=1;
data=0;
|
Showing 'what' the 'if' is expected to execute. |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Wed Jun 15, 2016 12:38 pm |
|
|
Thank you for the advice newguy
Following the same practice since I moved to "C" from ASM some 10 years ago. Started working again after a break of 5 years so going out from the rust slowly slowly.
The case I mentioned before happened by not out-commenting a temporary "if"
Best wishes |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Mon Jul 11, 2016 6:46 pm |
|
|
Update:
Got a new pcm.dll from CCS and the compilation problem solved
It was two weeks ago, I just missed the CCS answer
Best wishes
Joe |
|
|
|