View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
if { braces } in CCS code; intentional or not, unclear. |
Posted: Wed Jan 15, 2020 3:47 pm |
|
|
I found this in one of the CCS library routines:
Code: | if(m <= i)
i -= m;
done = 0; |
Note how both "i -= m;" and "done = 0;" are indented, which looks like the author intended for both of them to happen if the condition of "m <= i" were met. Perhaps they started out with one thing and added the second one less and forgot to add braces.
Or, perhaps done = 0 was intended to happen every time, and the tab was the mistake.
Because of the lack of braces, you can't tell the intent of the author.
"Always use braces." This has been a public service announcement. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Jan 15, 2020 4:21 pm |
|
|
I'd prefer this kind of format...
if(m <= i) i -= m; // what this is for..
done = 0; // clearing the variable..
If only once action due to the 'if', put that action on the same line as the 'if'.
I hate trying to 2nd guess some code,especially when it gives 'interesting' results and you don't know WHAT is supposed to be 'working code'..... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Jan 16, 2020 1:10 am |
|
|
It'd help if you said 'which file', since then we could look and work out what
the coder intended.
However this has almost certainly been caused by the CCS auto indent
behaviour. Unfortunately, this is not very smart and doesn't have good
rules to end the indentation, so if you indent the line after the 'if', it'll
keep indenting for following lines. The coder probably just 'missed' this. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 16, 2020 6:21 am |
|
|
It's in stdlib.h in the qsort() routine. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Jan 16, 2020 6:48 am |
|
|
My head hurts trying to figure out HOW PCMP KNEW which file it's in ! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Jan 16, 2020 8:04 am |
|
|
I know...
I tried a basic search but actually found each of the lines in dozens of
places.
He is very good at 'finding' things. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
Re: if { braces } in CCS code; intentional or not, unclear. |
Posted: Thu Jan 16, 2020 1:16 pm |
|
|
allenhuffman wrote: |
Because of the lack of braces, you can't tell the intent of the author.
"Always use braces." This has been a public service announcement. |
and then there was Python and chaos reigned _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Wed Jan 22, 2020 4:16 pm |
|
|
temtronic wrote: | My head hurts trying to figure out HOW PCMP KNEW which file it's in ! |
As he posted, yeah, similar things show up in various other spots. I just assume "it's supposed to work, so..." and go on. I only looked because of trying to figure out something with function pointers. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Feb 04, 2020 1:34 am |
|
|
Sometimes I think we have contestants in that here... |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Tue Feb 04, 2020 8:23 am |
|
|
Ttelmah wrote: | Sometimes I think we have contestants in that here... |
I learned some new tricks from one of last year's entry. I can see the appeal of compiler abuse :-)
e,n,j,o,y; _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
|