sizeof bug

I'm not sure if this is the right place to report a bug, moderators please feel free to move it to right place.

I'm running arduino-0022 on ubuntu 10.4 (avr-gcc 1:4.3.5-1, avrdude 5.10-3, etc proper dependencies delivered with the package from ubuntu repositories).

sizeof utility returns double the value of an int array.

#include "glcd.h"
#include "fonts/allFonts.h"         // system and arial14 fonts are used
#include "bitmaps/allBitmaps.h"       // all images in the bitmap dir 


int MyArray[]={6,7,8};
//char MyArray[]="hello";

void setup()
{
  GLCD.Init();
  GLCD.ClearScreen();
  GLCD.SelectFont(System5x7); // you can also make your own fonts, see playground for details   
  GLCD.CursorToXY(0,0);
  GLCD.print("Ready... ");
  GLCD.print("\n");

  GLCD.print("sizeof=");
  GLCD.print(sizeof(MyArray));
  GLCD.print("\n");
  
  for(int i=0; i< sizeof(MyArray); i++)  // >>>> yes, I realise is not sizeof()-1
  {
  GLCD.print(MyArray[i]);
  GLCD.print(",");
  }
  
  GLCD.print("\n");
  GLCD.print("And yet again, sizeof=");
  GLCD.print(sizeof(MyArray));
  GLCD.print("\n");

}

void loop()
{
}

The result on LCD is:

Ready...
sizeof=6
6,7,8,0,0,1865,
And yet again, sizeof=6

Using the char array (the one with "hello") from commented line with the proper sizeof()-1 in for statement, it is OK.

Regards.

You are misinterpreting the meaning of the sizeof() operator. It returns the size IN BYTES of its parameter, not the number of elements in the array.

If you want the number of elements in the array:

#define MyArraySize (sizeof(MyArray)/sizeof(MyArray[0]))
...
for (int i=0; i < MyArraySize; i++)
...

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

Wow, this must be a common misjudgement since I got an answer so fast. XD

Thanks a lot!