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

very interesting compilation

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



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

very interesting compilation
PostPosted: Wed Jun 13, 2012 2:18 am     Reply with quote

Hey,
How is this possible to compile? PCWHD 4.114.
I think it should never compile however it did ???

Code:
if (post_purge_count_time == 1)
    write_ic_rom (0x34, 0) ;
{ // post purge
 // do something
}


where

Code:
void write_ic_rom(LONG int location, int data)
{
   write_eeprom (location, data);
}   

_________________
Help "d" others and then you shell receive some help from "d" others.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: very interesting compilation
PostPosted: Wed Jun 13, 2012 2:37 am     Reply with quote

Linuxbuilders wrote:
Hey,
How is this possible to compile? PCWHD 4.114.
I think it should never compile however it did ???

Code:
if (post_purge_count_time == 1)
    write_ic_rom (0x34, 0) ;
{ // post purge
 // do something
}


where

Code:
void write_ic_rom(LONG int location, int data)
{
   write_eeprom (location, data);
}   


There's nothing wrong with that code. I don't know why you think it shouldn't compile, but it's perfectly good C syntax.

Maybe what you are worried about is the placement of the call to write_ic_rom(). What this code will do is conditionally call write_ic_rom() depending on the result of the if condition. Then it will always (not conditionally, nothing to do with the if) run the code in the "post purge" block. The curly block begin and end brackets aren't needed - as you don't declare any variables local to that block - but they are good syntax.

I think what you may have wanted was:

Code:
if (post_purge_count_time == 1)
{
    write_ic_rom (0x34, 0) ;
 // post purge
 // do something
}


Which is different. Both though are perfectly acceptable C syntax and should compile OK.

RF Developer
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Jun 13, 2012 3:04 am     Reply with quote

Other possibility, worried about 'long'?.
In C, types are _automatically_ converted to the type required by the target, if possible. Very powerful, but also dangerous. So the 0x34, gets converted to 0x0034 automatically.
Bracketing a code section, makes it behave logically as a single 'block'. Will change the meaning fractionally, if the 'block' returns a value, so is sometimes needed, and is perfectly legal.

Best Wishes
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