How to reference **ptr_xx to ptr_yy [xx][xx] - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: How to reference **ptr_xx to ptr_yy [xx][xx]

  1. #16
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245
    This works:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char* argv[])
    {
    #if 1
    	/***** try out Kevin method ****/
    	typedef char char_array_50[50];
    	typedef char char_array_500[500];
    
    	char_array_500 *zz = (char_array_500*) malloc(sizeof(char_array_500)*2000); // allocate char[2000][500]
    	
    	char_array_50 xx[30];
    	char_array_50* yy=(char_array_50*)&xx;
    #else
    	/**** try out sef method ****/
    
    	char (*zz)[500] = (char (*)[500]) malloc(sizeof(char)*500*2000); // allocate char[2000][500]
    	
    	char xx[30][50];
    	char (*yy)[50] = (char (*)[50])&xx;
    #endif
    
    	xx[3][5] = 7;
    	xx[7][8] = 11;
    	printf("A test... The next line should print '7, 11'\n");
    
    	printf("%d, %d\n", yy[3][5], yy[7][8]);
    
    	return 0;
    }

  2. #17
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245
    By the way, your code:

    Code:
    sht_pass_group = yy;
    will never work for the reasons I stated earlier about how memory is organized.

    - Kevin

Page 2 of 2 FirstFirst 12

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center