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

CCS's Non-Standard Functions

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



Joined: 27 Jul 2013
Posts: 79

View user's profile Send private message

CCS's Non-Standard Functions
PostPosted: Mon Jul 13, 2015 1:13 pm     Reply with quote

Many of the standard C functions are implemented in a very non-standard way by CCS.
For example:
isspace() returns true for only ' ' and not for tabs and line feeds.
atoi does not skip the spaces in the string before parsing, etc etc.

I understand that it is implemented this way for optimizations for limited memory and processing capabilities of pic.

My questions is, how do power users deal with this without having to spend hours debugging the code only to find the problem is with ccs's implementation of functions?

Also is there a way to override these functions without changing the names of functions to keep code portable and easy to understand.
temtronic



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

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 2:08 pm     Reply with quote

re: isspace() function

Works correctly for me. 'tabs(0x9)' and 'linefeeds(0x0a)' are NOT 'spaces'( 0x40).
My 'old school' thinking is that if another implementation says a 'linefeed' is 'space' then that's wrong ! THAT would really screw up 'parsing' and 'flagging'!

As for 'custom' functions.... just cut your own and call them something like .. 'my_isspace() say if you want to include tabs and linefeeds as spaces.

By using the prefix of 'my_' it'll remind you that it's YOUR function not the CCS one.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 2:51 pm     Reply with quote

The 'correct' definition for isspace, is 'space', 'tab' or 'newline'.

CCS implements it as space only.

You can define your own versions for any of the character match macros using isamong. They are in ctype.h.
They are only convenience macros, not functions.

You can add white space skipping to atol if required, but generally since if you are looking for a number to convert you will be searching for the number first it makes no difference. It's properly documented in the CCS manual.

The definitions for atol etc., are all in stdlib, and if you want leading suppression just add:
Code:

    for(index=0; isspace(s[index]);index++)
        ;

after the variable declarations.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 13, 2015 2:57 pm     Reply with quote

Here is a quick way to replace the CCS isspace() with a macro.
Just fill in the isamong() parameter list with whatever characters
you want to consider as spaces. The expanded version of isspace()
is shown below, but you could edit the macro to use the traditional
characters as Ttelmah says.

The isspace() macro is the #define statement. Most of the code below
is a test program. It has the following output in MPLAB 8.92 simulator:
Quote:
111111000000

Code:
#include <18F4620.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

// ' '  (0x20)   space (SPC)
// '\t'   (0x09)   horizontal tab (TAB)
// '\n'   (0x0a)   newline (LF)
// '\v'   (0x0b)   vertical tab (VT)
// '\f'   (0x0c)   feed (FF)
// '\r'   (0x0d)   carriage return (CR)

#define isspace(c)  isamong(c, " \t\n\v\f\r")

//===================================
void main()
{
int8 test_data[] = {' ','\t','\n','\v','\f','\r',1,2,3,'A','B','C'};
int8 *ptr;
int8 i;

ptr = test_data;

for(i=0; i<sizeof(test_data); i++)
   {
    printf("%u", isspace(*ptr++));
   }

printf("\r");

while(TRUE);
}
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