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

EEPROM read anomaly
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Fri Nov 10, 2023 10:18 am     Reply with quote

Ttelmah wrote:
Remember integers in CCS by default are unsigned....

-1 = 255

Do they? I didn't realise that every other compiler defaults to signed.
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Fri Nov 10, 2023 10:25 am     Reply with quote

Yes, the do while loop does the same thing though, yes I see the issue of evaluating the byte before reading it in, I could do an EEPROM read before going into the loop, but the for loop works as expected.

Thank you for your help!
gaugeguy



Joined: 05 Apr 2011
Posts: 281

View user's profile Send private message

PostPosted: Fri Nov 10, 2023 10:34 am     Reply with quote

BYTE loaded_code[512] = {};
EEPROM_ADDRESS number_of_lines = 0x00;

do
{
loaded_code[number_of_lines] = read_ext_eeprom (number_of_lines);
} while (loaded_code[number_of_lines++] != 0xFF)
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Fri Nov 10, 2023 10:46 am     Reply with quote

gaugeguy wrote:
BYTE loaded_code[512] = {};
EEPROM_ADDRESS number_of_lines = 0x00;

do
{
loaded_code[number_of_lines] = read_ext_eeprom (number_of_lines);
} while (loaded_code[number_of_lines++] != 0xFF)

Yeah that doesn't work, when the EEPROM is cleared it shows 1 instruction where it should show 0, which the for loop does.
Ttelmah



Joined: 11 Mar 2010
Posts: 19145

View user's profile Send private message

PostPosted: Fri Nov 10, 2023 10:55 am     Reply with quote

Wilksey wrote:
Ttelmah wrote:
Remember integers in CCS by default are unsigned....

-1 = 255

Do they? I didn't realise that every other compiler defaults to signed.


This is one of the things that changes if you select ANSI mode.

'Every other compiler', no.

This is 'historic'. When C was first launched, the authors specifically said
that the default size and type for an integer, should be the processor's
default.
So you had things like the early PDP-8 compilers using 18bit integers that
were not signed. The PDP-11 used unsigned 16bit. Some other chips used
10bit etc. etc.. CCS when they first launched their compiler kept with
this form, and use 8bit unsigned as the default. It was only later when
ANSI C became a 'semi standard', that compilers started to default to
using signed as the 'default'. CCS has retained this on the PIC12/16/18
but then on the PIC24/30/33 because the default integer type is signed,
the PCD compiler uses this.
It results in more efficient code by default, but requires that you are
aware of this.

So 'pretty much all modern compilers', yes. But by no means 'every other'.
Wilksey



Joined: 14 Aug 2011
Posts: 36
Location: Somerset, UK

View user's profile Send private message

PostPosted: Fri Nov 10, 2023 10:59 am     Reply with quote

Fair point, I should have said every other compiler I have used.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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