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

fat.c , signed int and EOF

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



Joined: 20 Oct 2007
Posts: 9

View user's profile Send private message

fat.c , signed int and EOF
PostPosted: Sat Oct 20, 2007 11:22 am     Reply with quote

Hi,
could you explain me why functions like fatgetc in FAT.c driver implementation of CCS compiler return signed int ( int8 ) instead signed int ( int16 ) like ANY other standart ANSI compilers ? It is impossible to detect from these functions end of file, because 8bit value cannot contain 8bit binary value and EOF.Detecting EOF from the stream->Flags value is not too much compatible with other C compilers.Why you dont use the standart functions ? It is due any code optimalization ?


Milos

signed int fatgetc(FILE* stream)
{
char ch; // character read in

// check to see if the stream has proper permissions to read
if(stream->Flags & Read)
{
// when the number of bytes until eof hit zero, we know we are at the end of any file
if(stream->Bytes_Until_EOF == 0)
{
stream->Flags |= EOF_Reached;
return EOF;
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Oct 21, 2007 8:15 am     Reply with quote

Quote:
could you explain me why functions like fatgetc in FAT.c driver implementation of CCS compiler return signed int ( int8 ) instead signed int ( int16 ) like ANY other standart ANSI compilers ?
1) This is a forum for users of the CCS compiler, the people of CCS don't monitor all messages (see the textbox on the top-right of every page of this forum). So for specific library internal questions this forum is not the right place.
2) The CCS compiler is not ANSI, it is a mixture of K&R, ANSI and C++ with a flavour of PIC specific add-ons.
3) ANSI does _not_ define an integer as 16 bit! This is left to the compiler builder to decide, for optimal code efficiency often based on the width of the processor's data bus (8 bits on a PIC, 16 bits on a 80286, 32 bits on a Pentium, etc). Using the #type specifier you can change the size of the compiler's data types if you want to.

Please keep in mind that the CCS supplied FAT driver is very new and you are one of the first user's. It is possible there are bugs and missing features. Please communicate your comments to support@ccsinfo.com so they will learn what we users think is important.

Note: I had a quick look at the FAT driver and I think you have a valid point. The CCS code is mixing signed and unsigned int8 variables, making it impossible to distinguish between a binary 0xFF in the file or an EOF (-1) being returned.
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