Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Passing vector to C function

Reply
Thread Tools

Passing vector to C function

 
 
Pallav singh
Guest
Posts: n/a
 
      12-02-2010
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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      12-02-2010
On 12/ 2/10 06:05 PM, Pallav singh wrote:
> HI
>
> i have code mixed of C++& C.
>
> can i pass vector<int> to a function in C.? how it can ve done


Assuming the function expects an int*, &vector[0];

--
Ian Collins
 
Reply With Quote
 
 
 
 
Fred Zwarts
Guest
Posts: n/a
 
      12-02-2010
"Pallav singh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Seg fault!: passing vector<vector<int> > to a function danielhdez14142@gmail.com C++ 2 02-09-2007 05:31 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
how the vector is created, how to pass vector to webservices method apachesoap:Vector Rushikesh Joshi Perl Misc 0 07-10-2004 01:04 PM



Advertisments