|
|
View previous topic :: View next topic |
Author |
Message |
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
very interesting compilation |
Posted: Wed Jun 13, 2012 2:18 am |
|
|
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
|
Re: very interesting compilation |
Posted: Wed Jun 13, 2012 2:37 am |
|
|
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
|
|
Posted: Wed Jun 13, 2012 3:04 am |
|
|
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 |
|
|
|
|
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
|