Simple c array in struct pointer question

i have a two struct like so:
typedef struct {
       uint8_t data[256];
} foo1;
typedef struct {
       uint32_t data_ptr;
} foo2;
foo1 * ctx;
foo2    ply;
if i want to get the pointer to the data array in ctx and assigned to data_ptr would i do it like so:
ply.data_ptr = &(ctx->data);

&(ctx->data) returns a pointer to an array of 256 integers. This type will look something like uint8_t (*data_ptr)[256]. Instead you should do what falconindy suggested above:
ply.data_ptr = ctx->data
To avoid gcc warnings (which you should always avoid), data_ptr needs to be declared the correct type of pointer. Since ctx->data by itself is nothing more than a pointer to an 8-bit wide integer you want (uint8_t *). ((void *) also works)

Similar Messages

  • Resizing an array of struct inside a DLL using the memory manager

    Hi all,
    I dug deep inside the boards, but wasn't able to find a solution for my problem.
    I'm building a dll, which does some imageprocessing and should return an array of structs to labview, with one struct for every element in the image.
    As I don't know the number of elements beforehand and the limit of the number is numbers of magnitude larger then the expected one, I don't want to allocate such a huge chunk of memory prior to the dll call in labview.
    In a former version I used a 2d array for the elements, where each row holds the values of every element. Here I used the NumericArrayResize-function, which worked quite well. But I have to add more sub-processes and using structs (or clusters in labview) appears to be more usefull and cleaner for me, in addition I had to cast some of the elements back and foreward a few times.
    So one element-struct should hold 2 singles and 1 uint32. My question is now, how can I resize this array of struct with memory manager functions as the NumericArrayResize-functions does not suit this purpose?
    (Accessing a given array of structs inside the DLL and after that reading the changed values in Labview is surprisingly easy )
    Thanks in advance
    Solved!
    Go to Solution.

    Well, I was able to solve it myself. I found this thread, where the first post of rolfk made me thinking. It appeared to me, that the numericarrayresize-function behaves very similar to the realloc-function of c. So I used the type unsigned int 8 (which is just one byte) and multiplied it by the number of bytes used by one struct, in my case 12 bytes (4+4+4) and then multiplied it by the number of structs (elements in the image) i have. Luckily it worked and the memory block was resized exactly as I wanted it to be. Important to note: do not forget to adjust the size element of the handle, otherwise Labview does not know about the changed size.

  • A SIMPLE int[ ] array is driving me nuts!

    ok, what am I doing wrong? I've read many other posts saying the same thing: arrays giving null pointer exceptions, but I can't find an intelligible answer:
    * Demonstrates simple arrays
    public class DemonstrateSimpleArrays
        private int[] anIntArray;
        private int[] anotherIntArray;
        public DemonstrateSimpleArrays()
            int[] anIntArray = {1,2,3};
            System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);
            int[] anotherIntArray = new int[3];
            anotherIntArray[0] = 4;
            anotherIntArray[1] = 5;
            anotherIntArray[2] = 6;
            System.out.println(anotherIntArray[0] + "" +
              anotherIntArray[1] + anotherIntArray[2]);
        public void printArrayValues()
            System.out.println(anotherIntArray[0] + "" +    //  Null Pointer Exception occurs here.
              anotherIntArray[1] + anotherIntArray[2]);
            System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);  //  Null Pointer Exception occurs here.
    }Thanks!

    my apologies: the code in my second emssage was incorrect. it did not include the second printArrayVariables method that I just added. see ammended:
    * Demonstrates simple arrays
    public class DemonstrateSimpleArrays
        private int[] anIntArray;
        private int[] anotherIntArray;
        public DemonstrateSimpleArrays()
            int[] anIntArray = {1,2,3};
            System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);
            int[] anotherIntArray = new int[3];
            anotherIntArray[0] = 4;
            anotherIntArray[1] = 5;
            anotherIntArray[2] = 6;
            System.out.println(anotherIntArray[0] + "" +
              anotherIntArray[1] + anotherIntArray[2]);
            printArrayValues(anotherIntArray, anIntArray);
        public void printArrayValues()
            System.out.println("Print Array Values:");
            System.out.println(anotherIntArray[0] + "" +   //Still Throws exception when this method is called.
              anotherIntArray[1] + anotherIntArray[2]);
            System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);
        public void printArrayValues(int[] anotherIntArray, int[] anIntArray)
            System.out.println("Print Array Values:");
            System.out.println(anotherIntArray[0] + "" +   //Does not Throw exception (thank goodness!)
              anotherIntArray[1] + anotherIntArray[2]);
            System.out.println(anIntArray[0] + "" + anIntArray[1] + anIntArray[2]);
    }

  • Floating point question

    I am trying to create a price attribute, so I need to places after the decimal point. I how do I set that when I create a table?

    Example from Help section in Oracle SQL Developer:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    With the OLAP and Data Mining options
    SQL> set serverout on
    SQL> DECLARE  -- Declare variables here.
      2    monthly_salary         NUMBER(6);  -- This is the monthly salary.
      3    number_of_days_worked  NUMBER(2);  -- This is the days in one month.
      4    pay_per_day            NUMBER(6,2); -- Calculate this value.
      5  BEGIN
      6  -- First assign values to the variables.
      7    monthly_salary := 2290;
      8    number_of_days_worked := 21;
      9
    10  -- Now calculate the value on the following line.
    11    pay_per_day := monthly_salary/number_of_days_worked;
    12
    13  -- the following displays output from the PL/SQL block
    14    DBMS_OUTPUT.PUT_LINE('The pay per day is ' || TO_CHAR(pay_per_day));
    15
    16  EXCEPTION
    17  /* This is a simple example of an exeception handler to trap division by zero.
    18     In actual practice, it would be best to check whether a variable is
    19     zero before using it as a divisor. */
    20    WHEN ZERO_DIVIDE THEN
    21        pay_per_day := 0; -- set to 0 if divisor equals 0
    22  END;
    23  /
    The pay per day is 109.05
    PL/SQL procedure successfully completed.
    SQL>It's not create table statement which you need but one can see in this example answer on your " Floating point question".
    HTH
    Message was edited by:
    Faust

  • How I average data with 78,74,73 and 55 points respectively and end up with an array of 78 points for the average?

    Hi
    As the questions states, how do I average data with 78,74,73 and 55 points respectively and obtain an array of 78 points? 
    When I use the plus vi, Labview somehow produces an array of 55 points when I do the average (see attached vi).
    I have been unlucky in trying to get good results.
    Can anyone help?
    Thank you.
    Attachments:
    average4.vi ‏40 KB

    The add function is polymorphic. It accepts arrays as well as numerics, but you need to understand one thing about array operations in LV. Operations performed on arrays of different sizes will always (I think) work based on the smallest array. For example, if you auto index 2 arrays of different sizes into a for loop, the number of times the loop will run will be the size of the small array. The same is true here - when you wire 2 arrays of different sizes to the add function, only the first N elements of the larger array get processed. The rest are dumped. That's why you get 55 elements.
    Attached is a modification of your VI which shows 2 things:
    The bottom part is your algorithm, only cleaned up. Note how much easier it would be to read now. You should always write clean code. Also, note that I have changed the representation on some of the data from DBL to I32. This is because this is the representation the array function work with and your code had the DBLs coerced for no reason.
    The top part is a different algorithm which should do what you want. Note that like Mike said, the arrays with smaller sizes will have 0s appended at the end, so if you want to avoid that, you will have to modify the last part, where the averaging is done and only divide those columns which are long enough.
    To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
    In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).
    Try to take over the world!
    Attachments:
    average4MOD.vi ‏63 KB

  • How do I pass a 1D LabView array as a pointer to an array in a C DLL?

    Hello,
    I am trying to pass a 1D Labview array of DOUBLE to a C DLL which is expecting a pointer to an array of DOUBLE.  I have read that LabView stores arrays as a pointer to a pointer and that the first element of a LabView array is actually the size of the array.  So I think my question is then how do I dereference the first pointer and pass in a pointer which points to the second element in the array?    
    Any thoughts out there?
    Thanks!

    Hi justyou,
    There are many, many resources on this topic, so I will guide you to the two most useful ones:
    The "Call DLL.vi" example that ships with LabVIEW explains how to use almost any data type when executing DLLs. The "Call DLL.vi" can be found by browsing the Example Finder.
    Integrating DLLs. This page is the portal for DLL interation related resources. Read the tutorials and try the examples...
    This should give you some ideas.
    Have fun!
    - Philip Courtois, Thinkbot Solutions

  • Array of Structs in cftree

    Hi,
    I am using an array of structs to populate the data in a cftree and cfloop query to fill the structs, this worked well initially, but as the data is increasing, it gets slower and slower, is there a solution for this ?
    <cfcomponent name="treeComp">
    <cffunction name=mytree>
    <cfargument name="path" required="Yes">
    <cfargument name="value" required="Yes">
         <cfset result = arrayNew(1)>
         <cfquery datasource="source" name="entries">
              SELECT value, name FROM data
         </cfquery>
         <cfloop query="entries">
                   <cfset item=StructNew()>
                   <cfset item.value=entries.value>
                   <cfset item.display=entries.name>
                   <cfset arrayappend(result,item)>
         </cfloop>
         <cfreturn result>
    </cffunction>
    </cfcomponent>
    tree.cfm
    <cfform>
    <cftree name="tree" format="html">
         <cftreeitem bind="cfc:treeComp.mytree({cftreeItemPath},{cftreeItemValue})">
    </cftree>
    </cfform>

    Hi Dan,
    thank you for the suggestion, but in this case, I have the value and the display fields that need to be stored, if I just loop over a query, I do not get the desired results. can you point me to the example you have seen ?
    Thanks

  • Pro*C: Getting array of structs from a PL/SQL procedure

    I am trying to create a stored procedure that will take the results of a select query, put them into an array of structures and send the entire array of structs back to the calling function in the C program.
    I currently do a select into a cursor and return each row one at a time over the network.
    Any syntax suggestions would be of help.
    null

    I am trying to create a stored procedure that will take the results of a select query, put them into an array of structures and send the entire array of structs back to the calling function in the C program.
    I currently do a select into a cursor and return each row one at a time over the network.
    Any syntax suggestions would be of help.
    null

  • 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

  • Case-lock exclamation point/question mark doesn't work

    I'm not sure if this is a bug or a design flaw, but when I'm typing I put case-lock on and exclamation point/question mark only work on the first type then it reverts to comma/period. I don't understand why this is allowed for letters but not punctuation.

    You are preaching to the wrong choir. You need to let Apple know how you feel about it.
    https://www.apple.com/feedback/ipad.html
    It will work if you hold down on the shift key and keep hitting the !!!!!! But it does not work as a "caps lock" feature.

  • Extproc: DLL function requires struct pointer, howto ?

    Hi there !
    Does anybody know if and how it's possible to pass
    a struct pointer like
    typedef struct _NETRESOURCE {
    DWORD dwScope;
    DWORD dwType;
    DWORD dwDisplayType;
    DWORD dwUsage;
    LPTSTR lpLocalName;
    LPTSTR lpRemoteName;
    LPTSTR lpComment;
    LPTSTR lpProvider;
    } NETRESOURCE;
    to an external DLL function ? Currently i've created
    a wrapper DLL which accepts ordinary datatypes and fills
    the struct properly. But i would like to have a more
    'generic' way to use DLLs.
    Any Ideas ??? Thanks in advance !

    Hi!
    I am also in need of the solution to this, but could not get it right yet!
    Would you perhaps share your current solution (writing the wrapper) with me?....
    I will keep you posted if I find a way of using ora_ffi with a C Struct
    Bye!

  • Re:I am fresher can any body giveme Interview point Questions

    Dear Friends,
    I  am fresher can any body giveme Interview point Questions.
    emailid:[email protected]
    Thanks in advance,
    KIRAN.

    http://www.sap-img.com/sap-fi.htm
    FICO Sample Questions
    FI/CO Interview Questions
    SAF FI Technical Interview Questions 1
    SAF FI Technical Interview Questions 2
    SAP FI/CO Sample Questions and Answers 1
    SAP FI/CO Sample Questions and Answers 2
    FI Errors and Probable Solutions
    SAP Financial Modules TC
    Some Important Tcodes for FI GL AR AP Asset
    SAP FI Transaction Code List 1
    SAP FI Transaction Code List 2
    Tcodes for Configuring Assets Accounting
    Useful Reports Tcode in SAP Financial Accounting
    The Financial Statement Closing Tcodes
    Profit and Loss Closing Tcodes
    Assets and Liabilities Closing Tcodes
    SAP FI CO Table
    Important Tables in SAP FI
    Important Tables in SAP CO
    Important Tables in SAP AA
    Regards,
    Rajesh Banka

  • Simple Java Array Question

    // This is how I was taught to make a simple array. You have to define the size first.
    String [] test1 = new String[4];
    test1[0] = "1";
    test1[1] = "2";
    test1[2] = "3";
    test1[3] = "4";
    out.println(test1[0]);
    out.println(test1[1]);
    out.println(test1[2]);
    out.println(test1[3]);
    //If the size is not defined in this second example, why does it still work?
    String [] test2 = {"1","2","3","4"};
    out.println(test2[0]);
    out.println(test2[1]);
    out.println(test2[2]);
    out.println(test2[3]);
    They both produce the same results.

    // This is how I was taught to make a simple array.
    You have to define the size first.
    String [] test1 = new String[4];
    test1[0] = "1";
    test1[1] = "2";
    test1[2] = "3";
    test1[3] = "4";
    out.println(test1[0]);
    out.println(test1[1]);
    out.println(test1[2]);
    out.println(test1[3]);
    //If the size is not defined in this second example,
    why does it still work?
    String [] test2 = {"1","2","3","4"};
    out.println(test2[0]);
    out.println(test2[1]);
    out.println(test2[2]);
    out.println(test2[3]);
    They both produce the same results.Umm..the size is just as well defined in your second as in your first...it is a four element array.
    The second way is akin to the first...also
    String[] s = new String[]{"Hello","I","contain","five","elements"};
    System.out.println(s[5]); Will compile..you will get a run-time ArrayIndexOutOfBoundsException (it is a 5 element array, 0-4, but java will not assume that the variable s is not changed between those two lines of code)..
    Array index/boundary checking is done at run-time, not compile-time.
    In fact:
    String[] s;
    //let's say up in the program
    //and
    public void printS(int i)
    System.out.println(s);
    Will also compile...and if something else happens to set s as a 10 element String array:
    printS(9);would work
    ~David

  • Simple (?) start point question.

    Why can't I drag the start point like I can drag the end point? It (the start point) won't budge. When I try to drag it, all that happens is all my regions are selected, but start is still at 1 1 1 1. Y?
    thanks!

    Go to File>Song Settings> Synchronization .. you will see a box there that for experimenting with the bar position - you are not tied always to 1 1 1 1

  • Simple conditional array question

    Hi -
    I need to create an array, but how big it is depends on some other influences. Here's a simplified version:
    if (dataRequest.equals("elves")){
    String[] arrayLoader={"tinky","winky","pinky","stinky"};
    } else if (dataRequest.equals("reindeer")){
    String[] arrayLoader={"dasher","dancer","rudolph"};
    } else if (dataRequest.equals("villians")){
    String[] arrayLoader={"snowmiser","heatmiser"};
    out.println(arrayLoader.length);When I run this, I get "arrayLoader.length cannot be resolved to a type", but if I put the arrayLoader.length statement within each of the conditional parts, a length is returned. For some reason, the value seems to be "forgotten" by the time I leave the conditional part of the code.
    What am I missing?

    Variables only exist within the block they are declared in. So each of those String arrays only has scope within its own curly braces.
    What you want is an ArrayList.
    http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html
    It's an array that is automatically sized as you add members to it.

Maybe you are looking for

  • Report builder not printing

    HI all, we were using Oracle Report 6i on windows XP Service pack 2, Oracle Database 10.1.0.2.0 On AIX 5.2 and SEDCO Magina L2200c printer was being used to print the reports from report Builder 6i and it was working fine. but now just we change the

  • BW Hierarchy not coming up in my WEBI report

    Hi Gurus, I have created BW query with only 2 fields 1) 0PROJECT 2) 0WBS Element and a key fig 'No of records'. I activated the hierarchy on 0WBS. Then created universe on this query. WBS hier has 6 levels so i in universe, I got 6 dimensions with L0

  • Desperate for Delay function - Deadline fast approaching...

    I am trying to do what I suspect is easy, and I've searched but not come up with what I need to do. In my project, I have 4 nav buttons in a nav bar. Press on one and it calls a .swf file that animates the actual pressed button photo larger onto the

  • Using the Quiz Template in form Central

    Can I enter an answer key in the quiz template and automatically score the quiz?

  • AS of today I cannot attach a file in FF 33.1 w/yahoo 1.32 toolbar?

    Had no problem attaching files yesterday but today the pdf file only loads to a point and then just sits there with the spinning wheel. Had the same problem with IE but after several tries, was able to attach the file and send the email with it. Noth