Pragma INTO_ROM does not affect the sizeof operator, so these are two different issues.
About pragma INTO_ROM: this pragma is only for the HIWARE object file format which noone I know is using these days.
So my simple advice: Don't use it. Using it wont help. It wont hurt either, but it does confuse.
About the sizeof issue. The Freescale compiler uses sizeof according to the ANSI-C standard. There are a few common traps to look out for when using sizeof tough.
Don't use sizeof for argument arrays. C does not support array to be passed by value, so the thing which looks like an argument array is in reality a pointer. I'm not even sure what sizeof returns for this case, I guess it returns the size of the pointer.
And a second ANSI C issue is to use sizeof with undefined objects/types. I guess this is what happened here orininally, although not sure.
This setup looks like this:
header.h:
extern const char arr[];
header.c:
#include "header.h"
const char arr[]= "Hallo";
main.c:
#include "header.h"
const int arr_length= sizeof(arr)/sizeof(arr[0]);
For this pattern, the arr_lengt does not work as sizeof is needing an array definition, the declaration in the header is not enough to compute the size.
If this is the setup, I use usually something like this:
header.h:
extern const char arr[];
header.c:
extern const int arr_length;
#include "header.h"
const char arr[]= "Hallo";
const int arr_length= sizeof(arr)/sizeof(arr[0]);
main.c:
#include "header.h"
As additional note, using a local, const and non static array should actually work fine. However it really is inefficient as it has to be allocated and initialized on the stack. Making it global or static will be a lot faster and generate less code.
The original code snippet (after making it compile) does give me a 10, so I'm not able to reproduce the problem with it.
Daniel
3: #pragma INTO_ROM
4: const unsigned char somearray[] = { 0x01,
5: 0x02,
6: 0x03,
7: 0x04,
8: 0x05,
9: 0x06,
10: 0x07,
11: 0x08,
12: 0x09,
13: 0x0A}; /* just some made up numbers*/
14:
15: #define NUM_BYTES sizeof(somearray)
16:
17: int i;
18: i=NUM_BYTES;
19: return i;
0000 a60a [2] LDA #10
0002 5f [1] CLRX
20: }
0003 81 [4] RTS