×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    442

    How to pass 2d array object in method after dynamic allocation?

    Hi

    My code is:
    Code:
    
    FLOAT** tot_ener = (FLOAT**)malloc(2 * sizeof(FLOAT*));
    for(x=0 ; x<2 ; x++)
       tot_ener[x] = (FLOAT*)malloc(4 * sizeof(FLOAT));
    
    adjust_ATH( gfp, tot_ener );
    
    
    static void
    adjust_ATH( lame_global_flags* const  gfp, FLOAT tot_ener[2][4] )
    {
    .
    .
    .
    }
    
    At the compilation time give me a following error:

    ..\src\lameencoder.c:495: illegal implicit conversion from 'float **' to
    ..\src\lameencoder.c:495: 'float (*)[4]'

    Why i am getting this error anybody have any idea or any solution?
    please please help me, I searched on google also but do not get any solution, please give me idea to solve this problem.

    Regards,
    SymbianTH

  2. #2
    Super Contributor
    Join Date
    Sep 2007
    Posts
    1,005

    Re: How to pass 2d array object in method after dynamic allocation?

    try this: adjust_ATH( gfp, (*tot_ener)[4] );

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: How to pass 2d array object in method after dynamic allocation?

    The error message is true, "type something[2][4]" means that you have consecutive elements of 'type' in the memory, just you want to index them as a 2D array, where the 2nd dimension runs between 0 and 3.
    On the other hand "type **something" is a completely different layout, it means that you have an 1D array of "type*"-s, pointers. There is no direct way to convert them back and forth.

  4. #4
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    442

    Re: How to pass 2d array object in method after dynamic allocation?

    Quote Originally Posted by wizard_hu_ View Post
    The error message is true, "type something[2][4]" means that you have consecutive elements of 'type' in the memory, just you want to index them as a 2D array, where the 2nd dimension runs between 0 and 3.
    On the other hand "type **something" is a completely different layout, it means that you have an 1D array of "type*"-s, pointers. There is no direct way to convert them back and forth.
    Hi

    Before change a code it's static declaration in following way
    FLOAT tot_ener[2][1024];

    But when i test application on mobile device gives me a panic KERN EXEC - 3 in this line, So I changed this static declaration and do dynamic declaration in following way.
    FLOAT** tot_ener = (FLOAT**)malloc(2 * sizeof(FLOAT*));
    for(x=0 ; x<2 ; x++)
    tot_ener[x] = (FLOAT*)malloc(1024 * sizeof(FLOAT));

    But now problem is in function it's pass like a 2D array, so now i can do? how to convert this and pass in parameter.

    static void adjust_ATH( lame_global_flags* const gfp,FLOAT tot_ener[2][1024] )
    {
    .
    .
    .
    }

    please help me.

    Regards,
    SymbianTH

  5. #5
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    442

    Re: How to pass 2d array object in method after dynamic allocation?

    Hi

    Thanks
    Now I solved my problem.

    I got reference from following link and solved my problem.

    http://www.java2s.com/Code/C/Pointer...a4x10array.htm

    Regards,
    SymbianTH

Similar Threads

  1. Replies: 0
    Last Post: 2008-09-27, 03:58
  2. Edining an imported vertex array object
    By Tesctassa in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2006-11-09, 16:39
  3. Array of object reference
    By netlogins in forum Symbian
    Replies: 1
    Last Post: 2006-09-08, 10:48
  4. Replies: 3
    Last Post: 2004-02-07, 07:31
  5. Replies: 0
    Last Post: 2003-02-27, 20:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×