Passing vector to C function

Discussion in 'C++' started by Pallav singh, Dec 2, 2010.

  1. Pallav singh

    Pallav singh Guest

    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
    Pallav singh, Dec 2, 2010
    #1
    1. Advertising

  2. Pallav singh

    Ian Collins Guest

    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
    Ian Collins, Dec 2, 2010
    #2
    1. Advertising

  3. Pallav singh

    Fred Zwarts Guest

    "Pallav singh" <> wrote in message
    news:
    > 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.
    Fred Zwarts, Dec 2, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pmatos
    Replies:
    6
    Views:
    23,723
  2. Replies:
    8
    Views:
    1,890
    Csaba
    Feb 18, 2006
  3. Replies:
    2
    Views:
    489
    David Harmon
    Feb 9, 2007
  4. Javier
    Replies:
    2
    Views:
    542
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    346
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page