How to convert c struct definitions to c++
-
iov[0] = (struct iovec) { .iov_base = &req, .iov_len = sizeof(req) }; I'm trying to convert a bit of code from the ss network utility to c++, and the above and similar keeps giving these errors: main.cpp|83|error: expected primary- expression before ‘struct’ main.cpp|83|error: expected ‘)’ before ‘struct’
-
Answer:
C++ doesn't support that syntax. Try this: iovec iov[2]; iov[0].iov_base = &req; iov[0].iov_len = sizeof req; /* ... */ Or maybe: iovec iov[] = { { &req, sizeof req }, /* ... */ } What you were trying is a C99 feature called "compound literals". Also, the .iov_base thing is called a "designated initializer".
mpnordland at Stack Overflow Visit the source
Other answers
Compound literals are not present in C++. You can assign the struct members individually as cnicutar suggested or you can also define a temporary object and then assign it to iov first array element. Like this: iovec iov_temp = {&req, sizeof req}; iov[0] = iov_temp;
ouah
Related Q & A:
- How to Convert Code from VB to C++?Best solution by Stack Overflow
- How to Convert a C++ Structure into C# Structure?Best solution by Stack Overflow
- How to convert xml to json in c#?Best solution by Stack Overflow
- How to convert this curl command in c#?Best solution by Stack Overflow
- How to convert Matlab .m file to C code?Best solution by mathworks.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.