[C] Passing an array in to a function [SOLVED]

Hello, everyone,
I'm writing a small unit testing library for myself for various C projects I've got on the go at the moment. Right now, it just consists of one function which accepts an array of tests (structs) and runs each one. The problem is that the array seems to disappear once I pass it in to the library function.
The library's only test code at the moment is:
#include "test.h"
enum TestResult testPass();
enum TestResult testFail();
int main()
struct Test tests[] = {
{"pass", testPass},
{"fail", testFail},
testRun(tests);
return 0;
enum TestResult testPass()
return PASS;
enum TestResult testFail()
return FAIL;
test.h:
#ifndef TEST_H
#define TEST_H
enum TestResult
PASS,
FAIL,
struct Test
char* name;
enum TestResult (*test)();
void testRun(struct Test*);
#endif /* TEST_H */
And test.c, which compiles to libtest.so:
#include <stdio.h>
#include "test.h"
#define ARRAY_LENGTH(array) ((int) (sizeof(array) / sizeof(*array)))
void testRun(struct Test* tests)
enum TestResult result;
int i;
for(i = 0; i < ARRAY_LENGTH(tests); i++)
if((result = tests[i].test()) == PASS)
fprintf(stderr, ".");
else if(result == FAIL)
fprintf(stderr, "F");
else
fprintf(stderr, "?");
fprintf(stderr, "\n");
I get a single newline as output for running the test code. (that last fprintf() call). In other words, ARRAY_LENGTH(tests) == 0.
I've tried several different ways of making the array accessible to the library, including making an extern variable in test.h (couldn't use the automatic array sizing declaration), making a static variable in test.c and initializing it with a function (the array still disappeared), and just passing it in to the function, as shown. What am I overlooking? The way I figure, an array is a pointer, meaning they (arrays) are always passed by reference, and I can therefore declare testRun() as taking a struct Test* without any using any complicated data structures to preserve the contents and make the client interface as simple as possible.
Last edited by Michael C. (2010-04-10 21:28:02)

Another widely used way of doing it, without having to pass the size, is to use null-terminated arrays.
You probably know that strings are null-terminated arrays of characters?
Well you can do the same with arrays that you define.
You would have something like:
struct Test tests[] = {
{"pass", testPass},
{"fail", testFail},
{NULL, NULL},
Then instead of using the size of the array, you just loop on its elements until you have the null element, then break.
You just have to make sure you always put this null element at the end of your arrays. And that the null element is really a null element, I mean you can choose anything but of course it shouldn't be a possible normal value of the array.

Similar Messages

  • Using BC4J to pass an array to a stored function

    I have successfully implemented the use of BC4J view objects to pass and retrive values from a stored database procedure/function as per Steve Muench's paper.
    What I am having difficulty achieving is passing through an array to a stored function. I have a multiple selection table where on submit, I retrieve the selected values and want to be able to put them in a array and pass them to a stored function.
    At the database level, I have created a nested table with one of the columns being a table of numbers. A wrapper function is called with the array type being one of the in parameters and the database updated.
    I am however having no luck building the array in my Java code and passing it to the database through an expert-only view object.
    I have :
    1. Database wrapper function has an extra parameter for the table of numbers (number(10))
    2. Changed the view object query to include the extra parameter (of type Number[])
    3. Changed the relevant view object and transaction Impl classes to pass through an array of oracle.jbo.domain.Number
    4. Update my test module class to
    -- Test module class
    String _am = "transaction2.transaction2module", _cf = "Transaction2ModuleLocal";
        String str1 = "String1";
        String str2 = "String2";
        String str3 = "String3";
        Number[] num4 = {new Number(1001),new Number(1002),new Number(1003),new Number(1004)};
        Transaction2Module testModule = (Transaction2Module)Configuration.createRootApplicationModule(_am,_cf);
        TxnResultType txnResult = testModule.getTxnResult(str1,str2,str3,num4);
    -- Transaction2ModuleImpl.java
    public ProcessTransactionImpl getProcessTxn()
        return (ProcessTransactionImpl)findViewObject("ProcessTxn");
      public TxnResultType getTxnResult(String p1, String p2, String p3, Number[] p4)
        return getProcessTxn().getTxnResult(p1, p2, p3, p4);
    -- ProcessTxnImpl.java
    public TxnResultType getTxnResult(String p1, String p2, String p3, Number[] p4)
        setWhereClauseParam(0,p1);
        setWhereClauseParam(1,p2);
        setWhereClauseParam(2,p3);
        setWhereClauseParam(3,p4);
        executeQuery();
        return ((ProcessTransactionRowImpl)first()).getTxnResult();
      }but the error message given is :
    oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: select transaction_wrapper(:0, :1, :2, :3) as txn_result from dual
    java.sql.SQLException: Invalid column type
         void oracle.jdbc.dbaccess.DBError.throwSqlException(java.lang.String, java.lang.String, int)
    Can anyone offer some suggestions ?
    Thanks,
    Brent

    Thanks for the reply - I had nearly given up on this ! I did add the setWhereClause statement as you suggested
    setWhereClause("p1=:0 and p2=:1 and p3=:2 and p4=:3");but still got the same error. I have posted the entire output which may help you see what's still going wrong (hopefully!)
    oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. 
    Statement: SELECT * FROM (select test_array(:0,:1,:2,:3) as result from dual) QRSLT  WHERE (p1=:0 and p2=:1 and p3=:2 and p4=:3)
         void oracle.jbo.server.QueryCollection.executeQuery(java.lang.Object[], int)
              QueryCollection.java:541
         void oracle.jbo.server.ViewObjectImpl.executeQueryForCollection(java.lang.Object, java.lang.Object[], int)
              ViewObjectImpl.java:2650
         void oracle.jbo.server.ViewRowSetImpl.execute(boolean, boolean)
              ViewRowSetImpl.java:523
         void oracle.jbo.server.ViewRowSetImpl.executeQuery()
              ViewRowSetImpl.java:564
         void oracle.jbo.server.ViewObjectImpl.executeQuery()
              ViewObjectImpl.java:2614
         java.lang.String mypackage5.TxnViewImpl.getResult(java.lang.String, java.lang.String, java.lang.String, oracle.jbo.domain.Number[])
              TxnViewImpl.java:25
         java.lang.String mypackage5.TransModuleImpl.getResult(java.lang.String, java.lang.String, java.lang.String, oracle.jbo.domain.Number[])
              TransModuleImpl.java:29
         void mypackage5.TestArray.main(java.lang.String[])
              TestArray.java:17
    ## Detail 0 ##
    java.sql.SQLException: Invalid column type
         void oracle.jdbc.dbaccess.DBError.throwSqlException(java.lang.String, java.lang.String, int)
              DBError.java:187
         void oracle.jdbc.dbaccess.DBError.throwSqlException(int, java.lang.Object)
              DBError.java:229
         void oracle.jdbc.dbaccess.DBError.throwSqlException(int)
              DBError.java:292
         void oracle.jdbc.driver.OraclePreparedStatement.setObject(int, java.lang.Object, int, int)
              OraclePreparedStatement.java:2782
         void oracle.jdbc.driver.OraclePreparedStatement.setObject(int, java.lang.Object)
              OraclePreparedStatement.java:2905
         boolean oracle.jbo.server.ViewRowSetImpl.bindParameters(java.lang.Object[], java.sql.PreparedStatement)
              ViewRowSetImpl.java:1313
         void oracle.jbo.server.QueryCollection.executeQuery(java.lang.Object[], int)
              QueryCollection.java:511
         void oracle.jbo.server.ViewObjectImpl.executeQueryForCollection(java.lang.Object, java.lang.Object[], int)
              ViewObjectImpl.java:2650
         void oracle.jbo.server.ViewRowSetImpl.execute(boolean, boolean)
              ViewRowSetImpl.java:523
         void oracle.jbo.server.ViewRowSetImpl.executeQuery()
              ViewRowSetImpl.java:564
         void oracle.jbo.server.ViewObjectImpl.executeQuery()
              ViewObjectImpl.java:2614
         java.lang.String mypackage5.TxnViewImpl.getResult(java.lang.String, java.lang.String, java.lang.String, oracle.jbo.domain.Number[])
              TxnViewImpl.java:25
         java.lang.String mypackage5.TransModuleImpl.getResult(java.lang.String, java.lang.String, java.lang.String, oracle.jbo.domain.Number[])
              TransModuleImpl.java:29
         void mypackage5.TestArray.main(java.lang.String[])
              TestArray.java:17
    Exception in thread main
    Process exited with exit code 1.I had to do a new example as I could not find the code I was using earlier. This is my java class
    import oracle.jbo.client.Configuration;
    import oracle.jbo.domain.Number;
    import mypackage5.common.TransModule;
    public class TestArray
      public static void main(String[] args)
        String _am = "mypackage5.TransModule", _cf = "TransModuleLocal";
        String str1 = "String1";
        String str2 = "String2";
        String str3 = "String3";
        Number[] num4 = {new Number(1001),new Number(1002),new Number(1003),new Number(1004)};
        TransModule testModule = (TransModule)Configuration.createRootApplicationModule(_am,_cf);
        String txnResult = testModule.getResult(str1,str2,str3,num4);
        System.out.println("Result = " + txnResult);

  • Passing an array argument to a function by referance

    Below is my function I want to call my function but there seems to be an error in the way I am calling it can you tell me the right syntax to use?
    The function accepts 3 arguments an array of ints, an array of booleans and an int.
    I am calling it as
    findamobileset ( citys, pointers, sizeofarrays);
    public void findamobileset (int citys[], boolean[] pointers, int sizeofarrays)
    int maxarraynumber = -1;
    int tempswap = -1 ;
    boolean runagain = false;
    for(int i = 0;i < sizeofarrays; i++){
    //if the mobile flag is pointing to the right: look at the +1 current position where on and if its bigger then make that the biggest k so far
    //ALSO check if its not pointing off the array
    if(pointers[i] == true && i !=citys[sizeofarrays] && citys[i+1] < citys[i] && citys[i] > maxarraynumber){
    maxarraynumber = citys;
    //if the mobile flag is pointing to the left: look at the +1 current position where on and if its bigger then make that the biggest k so far
    if(pointers[i] ==false && i != citys[0] && citys[i-1] < citys[i] && citys[i] > maxarraynumber){
    maxarraynumber = citys[i];
    //swap k with an ajacent integer the arrow is pointing too
    if(pointers[maxarraynumber] == true)
    tempswap = citys[maxarraynumber+1];
    citys[maxarraynumber+1] =citys[maxarraynumber];
    citys[maxarraynumber] = tempswap;
    else
    {  tempswap = citys[maxarraynumber-1];
    citys[maxarraynumber-1] =citys[maxarraynumber];
    citys[maxarraynumber] = tempswap;
    //reverse all numbers greater then k
    for(int i = 0;i < sizeofarrays; i++){
    if(citys[i] > maxarraynumber){
    if(pointers[i] == true){
    pointers[i]= false;}
    else
    pointers[i] = true;
    // print out the array
    for(int i = 0;i < sizeofarrays; i++){
    System.out.print(citys[i] + " ");
    System.out.println(" ");
    //test if theres a mobile integer left to redo it and flip the flag if there is
    for(int i = 0;i < sizeofarrays; i++){
    if(pointers[i] == true && i !=citys[sizeofarrays] && citys[i+1] < citys[i] ){
    runagain = true;
    if(pointers[i] ==false && i != citys[0] && citys[i-1] < citys[i] ){
    runagain = true;
    //recurviely call the algorithm again
    if(runagain == true){
    findamobileset ( citys, pointers, sizeofarrays);
    else
    {/terminate}

    1) There is no pass-by-reference in Java. At best, you have a reference that's passed.by-value (a copy of this reference, pointing to the same object).
    2) I won't read all of your code
    3) Which is unformatted anyway
    4) so I don't know what the error is. Maybe you care to tell me?

  • Passing an array as parameter from java (java controls) to stored procedure

    Hi,
    I'm using java controls (BEA Weblogic Workshop 8.1) to call a stored procedure and send an array as a parameter to the stored procedure from java. The following code below throws an exception "Fail to convert to internal representation".
    Java code
    import com.bea.control.DatabaseControl.SQLParameter;
    // Here i create the java array
    int[] javaArray={12,13,14};
    //The code below is used to create the oracle sql array for the procedure
    SQLParameter[] params = new SQLParameter[1];
    Object obj0=javaArray;
    params[0] = new SQLParameter(obj0, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
    // the code below calls the testFunc method in OJDBCtrl.jcx file
    String succ= dbControl.testFunc(params);
    OJDBCtrl.jcx
    * @jc:sql statement="call CMNT_TST_PROC(?))"
    String testFunc(SQLParameter[] param);
    The stored procedure used:
    TYPE SL_tab IS TABLE OF number INDEX BY PLS_INTEGER;
    Procedure cmnt_tst_proc (cmnt_tst sl_tab);
    Procedure cmnt_tst_proc (cmnt_tst sl_tab) is
    BEGIN
    dbms_output.put_line('Hello');
    END;
    I am getting the following exception
    Failure=java.sql.SQLException: Fail to convert to internal representation: [I@438af4 [ServiceException]>
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
    at oracle.jdbc.driver.DatabaseError.check_error(DatabaseError.java:861)
    at oracle.sql.ARRAY.toARRAY(ARRAY.java:210)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7768)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7449)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7837)
    at oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4587)
    at weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:244)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl._setParameter(DatabaseControlImpl.jcs:1886)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1732)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2591)
    at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:377)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:433)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:406)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:249)
    at com.bea.wlw.runtime.jcs.container.JcsContainer.invoke(JcsContainer.java:85)
    at com.bea.wlw.runtime.core.bean.BaseContainerBean.invokeBase(BaseContainerBean.java:224)
    at com.bea.wlw.runtime.core.bean.SLSBContainerBean.invoke(SLSBContainerBean.java:109)
    at com.bea.wlwgen.StatelessContainer_ly05hg_ELOImpl.invoke(StatelessContainer_ly05hg_ELOImpl.java:153)
    Can you please let me know, what i'm doing wrong and how i can pass an array to a procedure/function using java controls.
    Any help will be highly appreciated.
    Edited by: user12671762 on Feb 24, 2010 5:03 AM
    Edited by: user9211663 on Feb 24, 2010 9:04 PM

    Thanks Michael.
    Here's the final code that i used, this might be helpful for those who face this problem
    Java Code
    // Following code gets the connection object
    InitialContext ctx = new InitialContext();
    dataSource = (DataSource)ctx.lookup("<DataSourceName>");
    conn=dataSource.getConnection();
    // Following code is used to create the array type from java
    String query="CREATE OR REPLACE TYPE STR_ARRAY AS VARRAY(3) OF NUMBER";
    dbControl.runTypeQuery(query);
    // Following code is used to obtain the oracle sql array as SQLParameter
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("<schemaName>.STR_ARRAY", conn);
    Object[] elements = new Object[3];
    elements[0] = new Integer(12);
    elements[1] = new Integer(13);
    elements[2] = new Integer(14);
    oracle.sql.ARRAY newArray = new oracle.sql.ARRAY( desc, conn, elements);
    SQLParameter[] params = new SQLParameter[1];
    params[0] = new SQLParameter(newArray, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
    String succ= dbControl.testFunc(params);

  • How do I pass an array of structs to a C function using the dll flexible prototype adapter?

    What I want to do is pass into a C dll function a variably sized Array of structs of type TPS_Data. My Code compiles but when I run it in TestStand, I get an error -17001; Program Error. "Cannot allocate 0 size buffer Error in parameter 2, 'OpenFrdData'."
    I've allocated the Array of structs, and all of the information is there before I call my function, so is it my prototype? Or am I asking too much of the DLL Flexible Prototype Adapter to pass an Array of Structs?
    I can pass in a single struct of type TPS_Data and that works, but not an array.
    Here's the relevent code:
    typedef struct TPS_DATA
    char Report_Number[256];
    char System_Name[256];
    char Open_Date[256];
    char UUT_Part_Number[256];
    char UUT_Serial_Number[256];
    char UUT_Name[256];
    char Open_Employee_Name[256];
    char Open_Employee_Number[256];
    char Close_Employee_Name[256];
    char Close_Employee_Number[256];
    char Close_Date[256];
    } TPS_Data;
    typedef struct TPS_DATA_ARRAY
    TPS_Data DataRecord;
    } TPS_DataArray;
    long __declspec(dllexport) __stdcall OpenDialog (CAObjHandle Context, TPS_DataArray *TpsData[], const char *psFaultStr, char *sComments, const int nCount);

    OK,
    I can pass the data to the DLL function, using the following types:
    typedef struct StringArrayType
    char string[10][256];
    } StringArray;
    typedef struct MultiStringArrayType
    StringArray Record[10];
    } MultiStringArray;
    void __declspec(dllexport) __stdcall ATP_TestStructPassing(StringArray Strings)
    return;
    void __declspec(dllexport) __stdcall ATP_TestMultiStructPassing(MultiStringArray *Strings)
    return;
    But when the MultiStruct function Exits, TestStand reports an Error:
    -17501 "Unexpected Operating System Error" Source: 'TSAPI'
    There doesn't seem to be a way around this, and once the error occurs, I have to force quit TestStand. I've included the sequence file, and the dll code can be compiled from the fun
    ctions shown above.
    Any thoughts on how to get around this error would be greatly appreciated.
    Attachments:
    StructArrayPassing.seq ‏16 KB

  • How to pass an array to a function from a SELECT statement

    Hi all. I have a problem with passing an array to a function directly from a SELECT statement.
    Here is what I want. If I have a function
    function AAA(arrayVar <ArrayType>) return number;
    I want to be able to call this function this way
    select AAA((2,3,4))
    from dual
    or this way
    select AAA((10,12))
    from dual
    In other words I want to be able to pass an arbitrary number of numbers to the function. And I want this to work in a SELECT statement.
    Does anyone have any ideas how to implement this? What <ArrayType> should I use?(I've read about VARRAY, nested tables in the Oracle documentation but as far as I've understood these array types are meant to be used within PL/SQL blocks).
    I found only this http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:208012348074 through Google but it didn't help me.
    Thank you in advance.

    > What <ArrayType> should I use?
    SQL data types - as 3360 showed above. You cannot use PL/SQL structures and user types in the SQL Engine.
    You can however use all SQL structures and types in PL/SQL.
    Arrays in SQL is created as collection type - basic o-o. The collection type (or class) serve as a container for instantiated objects or scalar type.
    This is covered in detail in [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14260/toc.htm]
    Oracle® Database Application Developer's Guide - Object-Relational Features

  • Passing split array to function

    Anyone know how to pass an array to a function as seperate
    parameters i.e
    _array = [param1,param2,param3]
    functionToCall(param1,param2,param3)
    instead of: functionToCall(_array[0],_array[1],_array[2]);
    of having to go
    var1 = _array[0];
    var2 = _array[1];
    var3= _array[2];
    functionToCall(var1,var2,var3)
    Cheers, burnside

    DCIBurnside,
    > Marco Mind wrote:
    > Can't you just pass the array and indexs as a second
    array?
    That would only work if the desired function is written to
    accept two
    parameters formatted as arrays. DCIBurnside could certainly
    write an
    intermediary function, I suppose; but for that effort, it
    would be just as
    easy to pass in the parameters as already shown:
    functionToCall(_array[0],_array[1],_array[2]);
    Check out the methods of the Fuction class -- in particular
    Function.apply() -- which might be exactly what DCIBurnside
    is looking for.
    David Stiller
    Co-author, ActionScript 3.0 Quick Reference Guide
    http://tinyurl.com/dpsAS3QuickReferenceGuide
    "Luck is the residue of good design."

  • Passing array to call library function running on VxWorks (cRIO)

    Hello,
    I am using a cRIO 9012 running VxWorks.
    I have a Call library function VI in my application and I want to pass arrays of doubles to this function.
    The problem is that I can not access the values in the array.
    Here is the source code of my function:
    #include "D:\\Programme\\National Instruments\\LabVIEW 8.5\\cintools\\extcode.h"
    double avg_num(double *in1, double *out1)
        double ret;
        ret = in1[0] + out1[0];
        return ret;
    The value of in1[0] and out1[0] is always.
    When passing no arrays but single values, all is fine. But since my application is more complex than this example, I need to pass arrays.
    The block diagram and parameter specification is as shown in the attached screenshots.
    I am compiling the source code with the Gcc 6.3 which is available here:
    http://zone.ni.com/devzone/cda/tut/p/id/5694
    What am I doing wrong?
    Or is passing arrays not supported on cRIO?
    Maybe the makefile needs to be modified?
    Thank you.
    Best regards,
    Christian
    Attachments:
    vi.JPG ‏88 KB
    parameter.JPG ‏41 KB

    I guess I have solved the problem.
    The key was to set the parameter "Minimum size" for all function parameters to <None>.
    Having this, I can read the passed arrays. I do not know why this works but at the moment, it is ok for me.
    Thank you all.

  • Passing multidim array to c function

    Hi all,
    I am very new to JNI, so please excuse if asking something stupid. I want to pass amultidimensional array (double[][]) to a c++ function. The array holds a large matrix for a linear equation system, the c++ function is a solver.
    I can run "Hello World" using JNI, and I can pass a 1-dim double[] Array to a c++ function.
    If changing the native method argument from double[] to double[][], javah produces a c++ header file with jobjectArray as argument type. I don't understand, how to access the array within the c++ code.
    Can anyone give me a tip, how to do it? Most helpfull would be a c++ code line, that fetches an array...
    Thanks a lot,
    Clemente
    The generated header file:
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class Solver */
    #ifndef IncludedSolver
    #define IncludedSolver
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class: Solver
    * Method: solve
    * Signature: ([[DI)[D
    JNIEXPORT jdoubleArray JNICALL Java_Solver_solve
    (JNIEnv *, jobject, jobjectArray, jint);
    #ifdef __cplusplus
    #endif
    #endif
    Edited by: Clemente on Oct 15, 2007 2:15 AM
    Edited by: Clemente on Oct 15, 2007 3:37 AM
    Edited by: Clemente on Oct 15, 2007 3:42 AM
    Edited by: Clemente on Oct 15, 2007 3:43 AM

    Finally, I figured to access all dimensions. For the archive and anyone with similar problems:
    Assumed, that the provided jobjectArray is called "array", means the method looks something like:
    JNIEXPORT jdoubleArray JNICALL Java_de_vonmusil_vs_wqn_solver_Solver_solve(JNIEnv *env, jobject ob, jstring path, jobjectArray array) { [...] }
    following snippet lists the first two rows of the array of doubles:
         int j;
         jdoubleArray darray = (jdoubleArray) env->GetObjectArrayElement(array, 0);
         jdouble* first_element = env->GetDoubleArrayElements(darray, NULL);
         for (j=0; j<env->GetArrayLength(darray); j++)
              std::cout << "->" << first_element[j] << std::endl;
         darray = (jdoubleArray) env->GetObjectArrayElement(array, 1);
         first_element = env->GetDoubleArrayElements(darray, NULL);
         for (j=0; j<env->GetArrayLength(darray); j++)
              std::cout << "->" << first_element[j] << std::endl;
    Besides all the casting things, it works this way: A double[][] array is an array (a) of arrays (b). One can get a b-array with env->GetObjectArrayEalement(array, 0);.
    env->GetDoubleArrayElements(darray, NULL); fetches a pointer to the first double value and using the pointerarithmetic pointer[], one can iterate over the whole array.
    Thank you for all your help,
    Clemente
    Edited by: Clemente on Oct 15, 2007 1:26 PM

  • Passing an array as IN parameter to call a function

    I have a function the definition is
    TYPE VAR_VALUE_RECORD IS RECORD(VAR VARCHAR2(100),
                   VALUE VARCHAR2(100));
    TYPE VAR_VALUE_TAB IS TABLE OF VAR_VALUE_RECORD;
    FUNCTION GENERIC_WF(P_MSG_TYPE IN VARCHAR2,P_CDCS_NBR IN VARCHAR2, P_CDCS_SEQ IN VARCHAR2, P_DEBTORID IN NUMBER,
    P_EXTRAS IN VAR_VALUE_TAB) RETURN VARCHAR2;
    I am trying to call this function
    select WF_NOTIFICATIONS_PKG.GENERIC_WF('Manual Debt Establish Notification','2009A13636','001',105195359,'this is a test') from dual
    ERROR at line 1:
    ORA-06553: PLS-306: wrong number or types of arguments in call to 'GENERIC_WF'
    I am getting the above error, how do I pass the array as parameter.
    I will appreciate your help.
    Thnaks

    Hi,
    try this,
    Create OR Replace Package WF_NOTIFICATIONS_PKG Is
       Type VAR_VALUE_RECORD Is Record( VAR   Varchar2(100)
                                      , Value Varchar2(100));
       Type VAR_VALUE_TAB Is Table Of VAR_VALUE_RECORD Index BY Pls_Integer;
       Function GENERIC_WF( P_MSG_TYPE IN Varchar2
                          , P_CDCS_NBR IN Varchar2
                          , P_CDCS_SEQ IN Varchar2
                          , P_DEBTORID IN Number
                          , P_EXTRAS   IN VAR_VALUE_TAB ) Return Varchar2;
    End WF_NOTIFICATIONS_PKG;
    Create OR Replace Package Body WF_NOTIFICATIONS_PKG Is
       Function GENERIC_WF( P_MSG_TYPE IN Varchar2
                          , P_CDCS_NBR IN Varchar2
                          , P_CDCS_SEQ IN Varchar2
                          , P_DEBTORID IN Number
                          , P_EXTRAS   IN VAR_VALUE_TAB ) Return Varchar2 Is
       Begin
          Return ( P_EXTRAS(P_EXTRAS.First).var || ' - ' || P_EXTRAS(P_EXTRAS.First).Value );
       End GENERIC_WF;
    End WF_NOTIFICATIONS_PKG;
    SQL> Declare
      2     v_value_Tab WF_NOTIFICATIONS_PKG.VAR_VALUE_TAB;
      3     v_return    Varchar2(100);
      4  Begin
      5     v_value_Tab(1).var   := 'this is a test 1';
      6     v_value_Tab(1).value := 'this is a test 2';
      7 
      8     v_return := WF_NOTIFICATIONS_PKG.GENERIC_WF( 'Manual Debt Establish Notification'
      9                                                , '2009A13636'
    10                                                , '001'
    11                                                , 105195359
    12                                                , v_value_Tab );
    13 
    14     Dbms_Output.put_line(v_return);
    15  End;
    16  /
    this is a test 1 - this is a test 2
    PL/SQL procedure successfully completedRegards,
    Christian Balz

  • How do you pass an array of characters using the DLL functions

    I have exported C code into my DLL and I want to know how to pass an array of characters using LabVIEW.

    Mont;
    If you want to pass a string from LabVIEW to your dll, and you do NOT change size of the string, you can use a C String pointer (CStr), which is equivalent to (unsigned) char *.
    If you do modify size of the string, pass string as a LabVIEW structure (LStrHandle).
    The example "Passing a Variety of Data Types from DLL to LabVIEW" is an excellent starting point. Also make sure you check the manual "Using External Code in LabVIEW".
    Regards;
    Enrique
    www.vartortech.com

  • Passing an array in a for loop to a procedure

    I am trying to pass an array in a cursor for loop to a procedure which performs a table insert using the array's contents. Somehow I am missing something, or it is not possible. The compile error states: PLS-00306: wrong number or types in call to 'insert_address' I checked to be sure I am creating the arrays in both cases from similar data objects. Both address and work_address_table contain the same 4 columns with the same data types.
    create or replace package work_address as
    FUNCTION populate_address return boolean;
    procedure insert_address(in_address IN work_address_table%ROWTYPE);
    end work_address;
    create or replace package body work_address as
    function populate_address return boolean is
    cursor c1 is
    select 'H' as header,
    street1 as street
    city as city,
    NULL as state
    from address
    where city = 'HANOVER';
    TYPE addressT IS TABLE OF c1%ROWTYPE INDEX BY BINARY_INTEGER;
    rec1 addressT;
    BEGIN
    OPEN c1;
    FETCH c1 BULK COLLECT INTO rec1 LIMIT 500;
    FOR i IN 1..rec1.count LOOP
    rec1(i).state := 'US'
    insert_address(rec1(i));
    exit when c1%notfound;
    END LOOP;
    CLOSE c1;
    return TRUE;
    END populate_address;
    PROCEDURE insert_address(in_address IN work_address_table%ROWTYPE) IS
    BEGIN
    INSERT INTO work_address_table
    VALUES (in_address.header,
    in_address.street,
    in_address.city,
    in_address.state);
    COMMIT;
    END insert_address;
    END work address;
    /

    Both address and work_address_table contain the same 4 columns with the same data types.Are you 100% sure about this?
    SQL> declare
      cursor c1
      is
        select 1 deptno, dummy dname, 'Loc' location from dual;
      type addresst is table of c1%rowtype
        index by binary_integer;
      rec1   addresst;
      procedure p (d dept%rowtype)
      as
      begin
        dbms_output.put_line(d.dname);
      end p;
    begin
      rec1 (1).dname := 'z';
      p (rec1 (1));
    end;
    z
    PL/SQL procedure successfully completed.but changing just the first column of the cursor:
    SQL> declare
      cursor c1
      is
        select 'xy' deptno, dummy dname, 'Loc' location from dual;
      type addresst is table of c1%rowtype
        index by binary_integer;
      rec1   addresst;
      procedure p (d dept%rowtype)
      as
      begin
        dbms_output.put_line(d.dname);
      end p;
    begin
      rec1 (1).dname := 'z';
      p (rec1 (1));
    end;
    Error at line 3
    ORA-06550: line 20, column 3:
    PLS-00306: wrong number or types of arguments in call to 'P'
    ORA-06550: line 20, column 3:
    PL/SQL: Statement ignored

  • How to pass an array which in the jsp to a javascript file

    now i have 2 files: jsp and js(javascript)
    i want pass an array which in the jsp to another file--> js file
    how can i do it ???
    can u give me some related links or some source codes as the references???
    thx

    bcos ....my senior has resigned!!! so i take over his job !!!!!
    depend on the talent and the project ....only that way to implement to whole project !!!!
    but , i had settled it already ....
    it is very simple
    in the middle.jsp
    Collection result = menuManager.getUserRoleMenu(webSessionUser.getGnuserId());
    String menuname[]=new String[110];
    int menucounter=0;
    Iterator vi = result.iterator();
    while(vi.hasNext())
    HashMap hm=(HashMap)vi.next();
    menuname[menucounter]=hm.toString();
    menucounter++;
    int i;
    String tempstr="";
    for(i=0;i<menuname.length;i++)
    tempstr+=menuname[i]+",";
    session.setAttribute("menuname",tempstr);
    %>
    <script language="javascript">
    menu123("<%=tempstr %>");
    </script>
    in the body,js
    function menu123(string123)
    //doing
    so ....through the script --menu123
    i can get the string from jsp to the js!!!!!
    is it very simple, but it spends my 2 days!!!
    i just learn javascript ....about 1 month !!!

  • How to pass an array in Oracle Procedure

    If I have to pass an array as an argument in Oracle Procedure/function. How to do that ??
    For example, I have to pass the names of employess and then for these employess I have to do something in Oracle Procedure.
    Thanks & Regards,
    Vinay

    Hi!
    Here is an example:
    create or replace procedure test
    is
    type v2_itt is table of varchar2(2000) index by binary_integer;
    l_v2 v2_itt;
    procedure test2( pi_v2 v2_itt ) is
    begin
    for i in 1 .. pi_v2.count loop
    dbms_output.put_line( pi_v2(i) );
    end loop;
    end;
    begin
    l_v2(1) := 'name1';
    l_v2(2) := 'name2';
    test2( l_v2 );
    end;
    Regards,
    Andrew Velitchko
    BrainBench MVP for Developer/2000
    http://www.brainbench.com

  • How to pass an array to a subroutine in FXscript?

    Hi,
    I am having problems trying to pass an array to a subroutine in FXscript.  Code segment:
    on TestSub(value x)
    // do stuff
    end
    float i, testarray[256];
    for i = 0 to 255
              testarray[i] = i;
    next
    TestSub(testarray);
    FXscript returns the error "missing close parenthesis".  If TestSub(testarray) is replaced with TestSub(testarray[0]) no error, i.e. if a single value is passed.
    Trying to define the subroutine differently doesn't help, e.g. "on TestSub(value x[255])" or "on TestSub(float x[255])" yields the same error.
    How do you pass an array to an FXscript subroutine?  Or is it not possible?
    Thanks for any clues...

    You are not being quite clear.  If the next frame expects a pointer to a buffer, it cannot be a vi.  Labview has no pointer types.  You must be referring to a Call Library Node which is set up to call a DLL function.  If this is the case, you need to configure the Call Library Node to accept an array of the data type.  Then you can wire the array into the call library node.
    Is this the case, Call Library Node?
    - tbob
    Inventor of the WORM Global

Maybe you are looking for

  • What is the difference between an ipad with cellular and one without?

    Anyone?

  • Help me!  Flash won't download! :(

    Hello! Thank you in advance for taking the time to read this. I have not had Flash in about 4 months and so my internet does next to nothing I want it to... I try every week, sometimes several times, to fix this but it never works! I download it, say

  • Warning when tomcat4.1 started

    hi all, iam using tomcat 4.1. my applications r working fine but whenevr iam starting tomcat i get the foolowing error code: at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidato

  • Incorrect database version in CHECK-OS-DB-VERSION

    We are performing an upgrade to NetWeaver 7.3 on a Java-only stack that is running Portal components. We have started at NetWeaver 7.0 EhP1, on LINUX RH-EL 5 and ORACLE 11.2.0.1. We got stuck on the database check. The system reported that our databa

  • Row Highlighting

    I am trying to find a thrad / example showing how to do row highlighting using javascript. I want to highlight a row in a report by clicking on it. It is supposed to remain highlighted until I either reload / submit the form or click on an other row.