Thread: Function Parameters Corrupt

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    8

    Function Parameters Corrupt

    Hi,

    I'm new to this forum and was hoping someone could help me debug a sanity-questioning problem I'm having. Consider the following function declaration and call...


    Code:
    int encode_buffer(large_struct_t * gfp, const int buffer[16][2][1152],
                           int nsamples[16], unsigned char mp3buf[16][16384], 
    		       int mp3buf_size[16],
                           int num_frames_to_encode, 
                           int mp3sizes[16]);
    
    void my_func() {
        int mp3sizes[16];
        int mp3buf_size[16];
        int Buffer[16][2][1152];
        int num_frames_to_encode;
        large_struct_t *gf;
        unsigned char mp3buffer[16][16384];
        int iread_arr[16];
    
        ...
    
         encode_buffer(gf, Buffer, iread_arr, mp3buffer, mp3buf_size, 
                                num_frames_to_encode, mp3sizes);
    
        ...
    }
    For some reason, I'm experiencing some corruption of the function parameters, once the function is executed. When I step through the execution, I can see that just before the function call, all the values being passed are sane values, but once I step inside the function, the values become muddled. With this specific configuration, I lose the first dimension of each array. The address of these values remains the same, but somehow their contents is altered in the function call. The scalar value (num_frames_to_encode) remains consistently correct.

    I have also tried alternative function prototypes along the following lines:

    Code:
    int encode_buffer(large_struct_t * gfp, const int buffer[16][2][1152],
                           int nsamples[16], unsigned char *mp3buf[16], 
    		       int mp3buf_size[16],
                           int num_frames_to_encode, 
                           int mp3sizes[16]);
    Where the type of mp3 buf is "unsigned char *mp3buf[16]." In my mind, either of these prototypes should be fine (multidimensional arrays are represented as an array of pointers to an array, right?). I should note that this is part of a very large program, and doing simpler sanity checks reveal to me that at least the first prototype should be correct, given only this function and a call to it.

    If anyone has any ideas or solutions, I would greatly appreciate hearing them! Thanks!
    Last edited by cecomp64; 07-10-2008 at 11:43 AM. Reason: fix typo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. function with variable number of parameters
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 03:35 PM
  3. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM