Click here to Skip to main content
14,931,672 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Stefan_Lang8-Dec-19 23:01
mveStefan_Lang8-Dec-19 23:01 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
CPallini8-Dec-19 23:35
mveCPallini8-Dec-19 23:35 
AnswerRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Stefan_Lang8-Dec-19 22:47
mveStefan_Lang8-Dec-19 22:47 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Vaclav_9-Dec-19 3:33
MemberVaclav_9-Dec-19 3:33 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Stefan_Lang9-Dec-19 4:11
mveStefan_Lang9-Dec-19 4:11 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Vaclav_9-Dec-19 7:57
MemberVaclav_9-Dec-19 7:57 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Stefan_Lang9-Dec-19 20:32
mveStefan_Lang9-Dec-19 20:32 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Stefan_Lang9-Dec-19 5:41
mveStefan_Lang9-Dec-19 5:41 
P.S.: Based on this code segment:
struct hci_dev_list_req *dl;
struct hci_dev_req *dr;
int dev_id = -1;
int i, sk, err = 0;


dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));

I suggest the following struct definition:
struct hci_meta {
   std::array<hci_dev_req,HCI_MAX_DEV> my_hci_list;
   hci_dev_req& operator[](int i) {
      return my_hci_list[i];
   }
   hci_dev_list_req my_hci_req;
};
void foo() {
   hci_meta dl; // use new if you must, but so far I see no need
   hci_dev_list* dr = dl.my_hci_req;

   ...
   // use some hci element from the list:
   hci_dev_req current_dev_req = dl[i]; // invokes hci_meta::operator[](int)
   ...
}


No need for allocation, deallocation, or typedefs unless you have additional requirements you haven't mentioned yet.


P.S.: since the array in this case is embedded inside a struct, you could use a standard C array instead:
struct hci_meta {
   hci_dev_req my_hci_list[HCI_MAX_DEV];
   hci_dev_req& operator[](int i) {
      return my_hci_list[i];
   }
   hci_dev_list_req my_hci_req;
};

GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)


modified 10-Dec-19 2:57am.

QuestionRichard MacCutchan had 1.5 mg storage in CrichEditCtrl the answer Limittext Pin
ForNow1-Dec-19 13:55
MemberForNow1-Dec-19 13:55 
AnswerRe: Richard MacCutchan had 1.5 mg storage in CrichEditCtrl the answer Limittext Pin
Stefan_Lang1-Dec-19 20:59
mveStefan_Lang1-Dec-19 20:59 
GeneralRe: Richard MacCutchan had 1.5 mg storage in CrichEditCtrl the answer Limittext Pin
Richard MacCutchan1-Dec-19 22:09
mveRichard MacCutchan1-Dec-19 22:09 
QuestionModifying STREAMed input in a RichEditControl Pin
ForNow30-Nov-19 20:34
MemberForNow30-Nov-19 20:34 
AnswerRe: Modifying STREAMed input in a RichEditControl Pin
Richard MacCutchan30-Nov-19 22:52
mveRichard MacCutchan30-Nov-19 22:52 
GeneralRe: Modifying STREAMed input in a RichEditControl Pin
ForNow1-Dec-19 2:07
MemberForNow1-Dec-19 2:07 
GeneralRe: Modifying STREAMed input in a RichEditControl Pin
Richard MacCutchan1-Dec-19 7:14
mveRichard MacCutchan1-Dec-19 7:14 
GeneralRe: Modifying STREAMed input in a RichEditControl Pin
ForNow1-Dec-19 7:58
MemberForNow1-Dec-19 7:58 
GeneralRe: Modifying STREAMed input in a RichEditControl Pin
Richard MacCutchan1-Dec-19 8:04
mveRichard MacCutchan1-Dec-19 8:04 
GeneralRe: Modifying STREAMed input in a RichEditControl Pin
ForNow1-Dec-19 8:10
MemberForNow1-Dec-19 8:10 
QuestionHow read XLSX file without office automation? Pin
Le@rner19-Nov-19 0:22
MemberLe@rner19-Nov-19 0:22 
AnswerRe: How read XLSX file without office automation? Pin
Victor Nijegorodov19-Nov-19 0:53
MemberVictor Nijegorodov19-Nov-19 0:53 
AnswerRe: How read XLSX file without office automation? Pin
Richard Deeming19-Nov-19 1:14
mveRichard Deeming19-Nov-19 1:14 
GeneralRe: How read XLSX file without office automation? Pin
Le@rner19-Nov-19 1:36
MemberLe@rner19-Nov-19 1:36 
GeneralRe: How read XLSX file without office automation? Pin
Richard Deeming19-Nov-19 2:19
mveRichard Deeming19-Nov-19 2:19 
GeneralRe: How read XLSX file without office automation? Pin
Le@rner19-Nov-19 2:25
MemberLe@rner19-Nov-19 2:25 
AnswerRe: How read XLSX file without office automation? Pin
leon de boer19-Nov-19 2:43
Memberleon de boer19-Nov-19 2:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.