Dec 30, 2013 at 5:33am UTC
1 2 3 4
unsigned int * hci_buffer;
unsigned int hci_buff_size;
hci_buff_size = HCI_DAT_PKT_LEN * HCI_NO_PKTS; //!used macros
hci_buffer = new (nothrow) unsigned int [hci_buff_size];
Errors:
ISO C++ forbids declaration of ‘hci_buff_size’ with no type
line no 3: error: ISO C++ forbids initialization of member ‘hci_buff_size’
line no 3: error: making ‘hci_buff_size’ static
line no 3: error: ISO C++ forbids in-class initialization of non-const static member ‘hci_buff_size’
line no 3: error: declaration of ‘int hci_top::hci_buff_size’
line no 3: error: conflicts with previous declaration ‘unsigned int hci_top::hci_buff_size’
Last edited on Dec 30, 2013 at 5:33am UTC
Dec 30, 2013 at 5:34am UTC
What code comes before this code? Where is the code located? You have not provided enough information.
Dec 30, 2013 at 7:22am UTC
Its solved, But i have one more question:
unsigned int* hci_buffer;
hci_buffer = new(nothrow) unsigned int[hci_buff_size];
I want to initialize all locations of hci_buffer to zero. How it would be possible instead of initializing each location to zero??
Last edited on Dec 30, 2013 at 7:22am UTC
Dec 30, 2013 at 7:55am UTC
means if I write like
hci_buffer = {};
then hci_buffer would be initialized to zero;
Jan 3, 2014 at 8:00am UTC
then please tell me syntax to initialize hci_buffer
Jan 3, 2014 at 8:04am UTC
Last edited on Jan 3, 2014 at 8:04am UTC
Jan 3, 2014 at 11:48am UTC
empty pair of parentheses works too (and is pre-C++11, unlike the curlies)
unsigned int * hci_buffer = new unsigned int [hci_buff_size]();
Jan 6, 2014 at 8:57am UTC
hello EssGeEich,
Memory is destructed in the link in which you referred.
I don't want to destruct, just want to initialise with zero(like reset value).
Jan 6, 2014 at 9:00am UTC
Please read the code carefully.
Besides the fact LB posted the link (which you really didn't notice??), you should check out the 5th line.
There's even a comment - did you see it?
Jan 6, 2014 at 10:35am UTC
int *p = new int[10]{}; //notice the {}
delete[] p;
it means syntax in my case would b
unsigned int *hci_buffer = new int[10]{}; //Means need to add {} at the time of constructing ?
delete[] hci_buffer; //at time when need to initialize to zero?
Jan 6, 2014 at 2:49pm UTC
1 2
unsigned int *hci_buffer = new int [10]{};
//Means need to add {} at the time of constructing ?
^ Yes.
The {} initializes all the elements to 0.
The delete[] goes when you finished using hci_buffer.
Last edited on Jan 6, 2014 at 2:49pm UTC