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 support@ccsinfo.com

if { braces } in CCS code; intentional or not, unclear.

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



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

if { braces } in CCS code; intentional or not, unclear.
PostPosted: Wed Jan 15, 2020 3:47 pm     Reply with quote

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: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 15, 2020 4:21 pm     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Thu Jan 16, 2020 1:10 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 16, 2020 6:21 am     Reply with quote

It's in stdlib.h in the qsort() routine.
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 16, 2020 6:48 am     Reply with quote

My head hurts trying to figure out HOW PCMP KNEW which file it's in ! Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jan 16, 2020 8:04 am     Reply with quote

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. Very Happy
asmallri



Joined: 12 Aug 2004
Posts: 1630
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: if { braces } in CCS code; intentional or not, unclear.
PostPosted: Thu Jan 16, 2020 1:16 pm     Reply with quote

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: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Jan 22, 2020 4:16 pm     Reply with quote

temtronic wrote:
My head hurts trying to figure out HOW PCMP KNEW which file it's in ! Very Happy


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: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 03, 2020 4:30 pm     Reply with quote

Could be worse...
https://www.ioccc.org/
_________________
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 ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Tue Feb 04, 2020 1:34 am     Reply with quote

Sometimes I think we have contestants in that here... Very Happy
allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 04, 2020 8:23 am     Reply with quote

Ttelmah wrote:
Sometimes I think we have contestants in that here... Very Happy


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 ?
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