Click here to Skip to main content
14,936,787 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Richard MacCutchan8-Dec-19 22:21
mveRichard MacCutchan8-Dec-19 22:21 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Richard MacCutchan6-Dec-19 22:01
mveRichard MacCutchan6-Dec-19 22:01 
AnswerRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
CPallini8-Dec-19 22:09
mveCPallini8-Dec-19 22:09 
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 
Thanks for responding. It's good to know a little more context.

As for the "invalid pointer" error, I disagree with the notion of either using a simple C-style type cast, or reinterpret_cast. Both are only workarounds to a severe problem in your code. You're only telling your compiler to shut up, but that doesn't solve the problem that is causing this! All you'd achieve is that the program compiles - and then crashes at run-time!

To properly implement this in C++, the first step is to analyze how that pointer is being used, and what data fields are supposed to be accessed via this pointer. There are two possibilities:

1. all fields being accessed are data members of struct hci_dev_list_req . If this is the case, the malloc() statement from the original code is garbage (both of them). In C++, you should declare dl as follows:
std::array<hci_dev_list, HCI_MAX_DEV> dl;

There's no need for type casts, and no need for allocation or cleaning up - std::array takes care of that.

2. Some fields being accessed are not members of struct hci_dev_list_req . In this case the declaration of dl is garbage! dl is not a pointer to some struct or array of structs. Instead it's a pointer to some undefined struct which, among other things, contains hci_dev_list_req elements. And that is exactly how it should be declared. So, if the original C program does not provide the appropriate struct definition, you should create one yourself.
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)

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 
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 

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.