Click here to Skip to main content
15,499,571 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
arnold_w9-Sep-20 12:33
Memberarnold_w9-Sep-20 12:33 
AnswerRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Mircea Neacsu9-Sep-20 13:11
mvaMircea Neacsu9-Sep-20 13:11 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
arnold_w9-Sep-20 13:28
Memberarnold_w9-Sep-20 13:28 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Randor 9-Sep-20 13:44
professional Randor 9-Sep-20 13:44 
AnswerRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Joe Woodbury9-Sep-20 13:38
professionalJoe Woodbury9-Sep-20 13:38 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
arnold_w9-Sep-20 15:35
Memberarnold_w9-Sep-20 15:35 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Joe Woodbury9-Sep-20 16:14
professionalJoe Woodbury9-Sep-20 16:14 
GeneralRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
Stefan_Lang15-Sep-20 4:34
mveStefan_Lang15-Sep-20 4:34 
Note that C arrays do not include length information! So unless your function Function(uint8_t*) somehow knows how many elements there are, you'd also have to pass the number of elements as a separate parameter! And even if it does know how many elements to expect, there's always a chance someone calls it accidentally with a different number of elements.

The class std::vector behaves like an array, but internally it does store the array length which makes the code examples above feasible. You could of course write a C++ wrapper that calls a C function internally, like this:
C++
void Function(uint8_t* values, unsigned long int size); //normal C function implemented elsewhere
void Function(const std::vector<uint8_t>& values) {
    Function(values.data(), values.size());
}
int main() {
    Function({1, 2, 3});
    return 0;
}

Otherwise, you'd have to think of another way to pass the element number reliably.
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)

AnswerRe: What's the closest thing to an anonymous struct/array I can achieve that compiles with GCC? Pin
arnold_w11-Sep-20 13:46
Memberarnold_w11-Sep-20 13:46 
QuestionCWinThread for background processing Pin
Richard Andrew x645-Sep-20 11:13
professionalRichard Andrew x645-Sep-20 11:13 
AnswerRe: CWinThread for background processing Pin
Mircea Neacsu5-Sep-20 17:18
mvaMircea Neacsu5-Sep-20 17:18 
GeneralRe: CWinThread for background processing Pin
Richard Andrew x645-Sep-20 18:03
professionalRichard Andrew x645-Sep-20 18:03 
AnswerRe: CWinThread for background processing Pin
Randor 5-Sep-20 17:44
professional Randor 5-Sep-20 17:44 
GeneralRe: CWinThread for background processing Pin
Richard Andrew x645-Sep-20 18:01
professionalRichard Andrew x645-Sep-20 18:01 
GeneralRe: CWinThread for background processing Pin
Randor 5-Sep-20 18:29
professional Randor 5-Sep-20 18:29 
PraiseRe: CWinThread for background processing Pin
CPallini7-Sep-20 2:33
mveCPallini7-Sep-20 2:33 
QuestionGroup policy editor api Pin
Member 1487268131-Aug-20 0:13
MemberMember 1487268131-Aug-20 0:13 
AnswerRe: Group policy editor api Pin
Richard MacCutchan31-Aug-20 2:27
mveRichard MacCutchan31-Aug-20 2:27 
QuestionRe: Group policy editor api Pin
Member 1487268131-Aug-20 18:08
MemberMember 1487268131-Aug-20 18:08 
AnswerRe: Group policy editor api Pin
Richard MacCutchan31-Aug-20 21:57
mveRichard MacCutchan31-Aug-20 21:57 
GeneralRe: Group policy editor api Pin
Member 1487268131-Aug-20 22:33
MemberMember 1487268131-Aug-20 22:33 
GeneralRe: Group policy editor api Pin
Richard MacCutchan31-Aug-20 22:40
mveRichard MacCutchan31-Aug-20 22:40 
AnswerRe: Group policy editor api Pin
Randor 2-Sep-20 0:24
professional Randor 2-Sep-20 0:24 
QuestionWindows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
jackngill30-Aug-20 13:01
Memberjackngill30-Aug-20 13:01 
AnswerRe: Windows XP Convert SystemDrive Variable e.g. %SystemDrive% - into equivelant C++ code Pin
Mircea Neacsu30-Aug-20 17:47
mvaMircea Neacsu30-Aug-20 17:47 

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.