CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

CCS PCH C Compiler, v5.059 SOLVED

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

CCS PCH C Compiler, v5.059 SOLVED
PostPosted: Mon Jun 13, 2016 10:13 pm     Reply with quote

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.
Code:
if(data==0)

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

View user's profile Send private message

PostPosted: Tue Jun 14, 2016 12:08 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 14, 2016 12:55 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jun 14, 2016 1:03 am     Reply with quote

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. Smile
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Tue Jun 14, 2016 6:21 am     Reply with quote

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. Confused
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 14, 2016 6:34 am     Reply with quote

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 Smile

Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Tue Jun 14, 2016 6:54 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 15, 2016 12:38 pm     Reply with quote

Thank you for the advice newguy Smile
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

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 11, 2016 6:46 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group