Thread: New at Array and Pointers , Quick Question

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    32

    Question New at Array and Pointers , Quick Question

    Okay i was reading up on array and pointers, i have a function which requires the following input below and i want to know if im correctly placing the syntax for it :
    Code:
    #include <cextdecs(PROCESS_GETINFOLIST_)>
    short PROCESS_GETINFOLIST_ (short *ret-attr-list ,short ret-attr-count ,short *ret-values-list ,short ret-values-maxlen ,short *ret-values-len )
    Code:
    short *ret_val_length;
    short attr_list[3] ={2,4,22};
    short vals_list[20];
    short *ret_attr_list = attr_list ;
    short *ret_vals_list= vals_list;
    short ret_attr_count = 3;
    short ret_values_maxlen = 8192;
    
    main()
    {
      result = PROCESS_GETINFOLIST_ (&ret_attr_list, ret_attr_count, &ret_vals_list, ret_values_maxlen, &ret_val_length);
    Also my question is the unary & operator required for &ret_attr_list? if im referencing the entire array?!
    Thank you for the help.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need to pass a short*. If your variable is a short* already, then taking & will make it Something Else.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    32
    So the & is not required, in the book it says the & is used to retrieve the address and copy it to the content of the pointer.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Yes. &ret_attr_list is the address of ret_attr_list. That's not what you want, though; you want the address of the data (the bunch of shorts) itself. The value of ret_attr_list is the address of the data itself.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    The definition of ret_val_length is wrong. You declared it as a pointer, then pass it in by address (which is a short **, not a short *). Also, it doesn't actually point to a valid memory location that contains a short, it points into some random place that will likely cause your program to crash. You want to declare it as a plain old short, and pass in the address, like so:
    Code:
    short ret_val_length;
    ...
    result = PROCESS_GETINFOLIST_ (ret_attr_list, ret_attr_count, ret_vals_list, ret_values_maxlen, &ret_val_length);
    Also, you can't use a hyphen in an identifier name, so in your prototype, ret-attr-list et al, should be changed to something like ret_attr_list. Identifiers should start with a letter, and contain only letters, numbers and underscore.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hello all quick pointers question
    By dogger in forum C Programming
    Replies: 11
    Last Post: 05-22-2011, 09:03 AM
  2. Replies: 7
    Last Post: 05-19-2010, 02:12 AM
  3. Quick question on pointers
    By newbie30 in forum C Programming
    Replies: 3
    Last Post: 01-13-2010, 03:46 AM
  4. A quick question about pointers.
    By waynex in forum C Programming
    Replies: 6
    Last Post: 03-04-2008, 07:12 AM
  5. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM