View previous topic :: View next topic |
Author |
Message |
Wilksey
Joined: 14 Aug 2011 Posts: 36 Location: Somerset, UK
|
|
Posted: Fri Nov 10, 2023 10:18 am |
|
|
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
|
|
Posted: Fri Nov 10, 2023 10:25 am |
|
|
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: 303
|
|
Posted: Fri Nov 10, 2023 10:34 am |
|
|
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
|
|
Posted: Fri Nov 10, 2023 10:46 am |
|
|
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: 19538
|
|
Posted: Fri Nov 10, 2023 10:55 am |
|
|
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
|
|
Posted: Fri Nov 10, 2023 10:59 am |
|
|
Fair point, I should have said every other compiler I have used. |
|
|
|