WinAVR

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone.
I can not understand why the compiler gives an error on something like this:

char mas[0x10];
char size = sizeof(mas);
char *b = &mas[0x00];
char *c = b; //4
char *d = c + size; //5

int main(void)
{
}

../Temp.c:4: error: initializer element is not constant
../Temp.c:5: error: initializer element is not constant

What should I do?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

antonydublin wrote:
What should I do?
Step 1: read a book about C, preferably K&R.

antonydublin wrote:

../Temp.c:4: error: initializer element is not constant

The error message is fairly clear. An initializer must be a compile-time (or link-time) constant. You've given a value involving a variable. Change your code to comply with the C language requirement.
char *b  = &mas[0x00];
char *c = &mas[0x00];
char *d = &mas[0x00] + sizeof(mas);

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alternatively, declaring variables b, c, and size with the 'const' keyword should also work.