Passing vector to C function

P

Pallav singh

HI

i have code mixed of C++ & C.

can i pass vector<int > to a function in C.? how it can ve done

Thanks
Pallav Singh
 
F

Fred Zwarts

Pallav singh said:
HI

i have code mixed of C++ & C.

can i pass vector<int > to a function in C.? how it can ve done

Your question cannot be answered unambiguously.
C is not object oriented. You can pass an address of a vector to a C function,
but C will not be able to handle the vector, because it does not know about
the internal structure of it.
You need to provide more information about what the C functions needs.
If the C function needs to modify the size of the vector, than it will be close to impossible.
If the C function needs only access to the elements of the vector
it may be sufficient to pass it a pointer to the first element of the vector
and the size of the vector in another parameter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top