Click here to Skip to main content
15,893,814 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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
Stefan_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
Stefan_Lang8-Dec-19 22:47 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Vaclav_9-Dec-19 3:33
Vaclav_9-Dec-19 3:33 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Stefan_Lang9-Dec-19 4:11
Stefan_Lang9-Dec-19 4:11 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Vaclav_9-Dec-19 7:57
Vaclav_9-Dec-19 7:57 
GeneralRe: Allocating memory for struct pointer - error: invalid conversion from ‘void*’ Pin
Stefan_Lang9-Dec-19 20:32
Stefan_Lang9-Dec-19 20:32 
I'm not sure I understand. If the variables you called dl and dr are part of your code, then surely it is in your hands how to define and use them? If any code breaks, it is an indication that code was bad to start with. I'm not surprised though: there must have been a reason for the odd malloc statements, and my suspicion, as stated before, is that someone uses these pointers not as pointer to some struct array, but as a pointer to some meta-struct: see my other posting with a suggestion how to declare such a struct.

If you don't fix that broken code, it won't be clean. And reinterpret_cast does not fix anything. It only makes your code compile, but it doesn't make it work, much less clean.

I do not suggest to fix or change the structs hci_dev_req and hci_dev_list_req themselves, only the code using them. That code defines variables called dl and dr, and the way these are allocated currently indicates that code is broken and needs to be fixed. And that includes any code that uses dl and dr.

If for some reason you can't get std::array to work even though it does not require C++11, you could try std::vector instead: the main difference is that std::vector does not require the size to be known at compile time, and it can be resized dynamically. If HCI_MAX_DEV is a constant, std::array should work just fine; otherwise you need std::vector.

Of course, you can't pass a std::array into ioctl where it requires a hci_dev_list_req - you first need to convert it. That is not unusual for modern C++ code using old C APIs: in such cases you need some helper or wrapper functions that perform these conversions under the hood.

If you want to avoid these conversions, then the task you're asking for is an entirely different one - you should have stated that much from the beginning. Then we could have told you that it's not a good idea to transport a hackish C struct into C++ code and expect the resulting code to be 'clean'.
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
Stefan_Lang9-Dec-19 5:41
Stefan_Lang9-Dec-19 5:41 
QuestionRichard MacCutchan had 1.5 mg storage in CrichEditCtrl the answer Limittext Pin
ForNow1-Dec-19 13:55
ForNow1-Dec-19 13:55 
AnswerRe: Richard MacCutchan had 1.5 mg storage in CrichEditCtrl the answer Limittext Pin
Stefan_Lang1-Dec-19 20:59
Stefan_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
ForNow30-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
ForNow1-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
ForNow1-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
ForNow1-Dec-19 8:10 
QuestionHow read XLSX file without office automation? Pin
Le@rner19-Nov-19 0:22
Le@rner19-Nov-19 0:22 
AnswerRe: How read XLSX file without office automation? Pin
Victor Nijegorodov19-Nov-19 0:53
Victor 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
Le@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
Le@rner19-Nov-19 2:25 

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.