Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scalar object requires one element in initializer

Tags:

c

pointers

Why when I want to initialize the following vector of uint8_t

uint8_t *mmac_source1 = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x01 };

I get this error

Error: scalar object 'mmac_source1' requires one element in initializer

But when I am using this :

uint8_t mmac_source1[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x01 };

it's working fine.

like image 420
Roxana Istrate Avatar asked Jul 23 '14 08:07

Roxana Istrate


1 Answers

uint8_t *mmac_source1 = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x01 }; 

Here you don't memory allocated to the pointer. mmac_source1 just acts as a place holder wherein you can store an address.

uint8_t mmac_source1[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x01 };

Here you have an array where in your compiler allocates sizof(uint8_t)*6 bytes.

like image 163
Ginu Jacob Avatar answered Oct 06 '22 10:10

Ginu Jacob