Thread: problem with array

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    problem with array

    What is wrong with this code?

    It says that when i set
    int x = myarray[0][0];
    that there is no array(Specific subscript on non array or too many dimensions)


    #include <reg52.h>
    #include <stdio.h>
    #define XBYTE ((unsigned char volatile xdata*) 0)


    static char sxima[3][4] = {
    {4, 3, 0, 0},
    {0x00, 0xFF, 0x00, 0xFF},
    {0xFF, 0x00, 0xFF, 0x00}
    };


    void display1(int x_page, int y_dimension, int myarray){

    int x = myarray[0][0];
    int y = myarray[0][1];

    int i, j;

    for (j=1; j <x-1; j++) {
    for (i=0; i<y-1; i++) {

    myarray[j][i];

    }
    }


    }

    void main(void) {
    display1(2, 10, sxima);
    }

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    30
    but i want to use the display1 function several times with different arrays to import and different array dimensions.

    What can i do about this?

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    I'm posting here, because you didn't use code-tags , not just you, a lot of new members, this event is starting to be boring, always people forget or even didn't read about the code tags.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    30
    ok, sorry

    i didn't know it.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    30

    redesigned but problems in linking!!!

    I tried to redesign it, there is not problem in debugging but there are a lot of errors in linking. The problems are saying:

    ERROR 104: MULTIPLE PUBLIC DEFINITIONS
    WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
    I don't have enough experience so i do not know what to do.

    could you have a look at the code?

    Code:
    #include <reg52.h>
    #include <stdio.h>  
    #define XBYTE ((unsigned char volatile xdata*) 0)
    void delay(void);
    
    
    void data_enable1(void) {
    delay();
    XBYTE[0x8002] = 0x06; // E=0
    delay();
    XBYTE[0x8002] = 0x16; // E=1
    delay();
    XBYTE[0x8002] = 0x06; // E=0
    }
    
    
    void instr_enable1(void) {
    delay();
    XBYTE[0x8002] = 0x04; // E=0
    delay();
    XBYTE[0x8002] = 0x14; // E=1
    delay();
    XBYTE[0x8002] = 0x04; // E=0
    }
    
    
    void data_enable2(void) {
    delay();
    XBYTE[0x8002] = 0x0A; // E=0
    delay();
    XBYTE[0x8002] = 0x1A; // E=1
    delay();
    XBYTE[0x8002] = 0x0A; // E=0
    }
    
    
    void instr_enable2(void) {
    delay();
    XBYTE[0x8002] = 0x08; // E=0
    delay();
    XBYTE[0x8002] = 0x18; // E=1
    delay();
    XBYTE[0x8002] = 0x08; // E=0
    }
    
    
    
    void delay(void) { 
    unsigned int d;
    for (d=0; d<20; d++);}
    
    
    
    void display1(int x_page, int y_dimension, int x, int y, unsigned char volatile xdata *myarray) {
    
    //      *(myarray+ x*YPOS+XPOS);
     
    int i, j;
    
    	for (j=0; j<x; j++) {
    	unsigned int b = 184 + x_page + x;
    			
    			delay();
    			XBYTE[0x8000] = b;
    			instr_enable1();	
    
    
    			for (i=0; i<y; i++) {
    			unsigned int c = 64 + y_dimension + y;
    					delay();
    					XBYTE[0x8000] = c;
    					instr_enable1();
    
    					delay();
    					XBYTE[0x8000] = *(myarray+ x*j+i);
    					data_enable1();
    			
    			}
    	}
    
    
    }
    
    void main(void) {
    unsigned char volatile xdata* XMEM;
    
    unsigned char volatile xdata sxima[3][4] = {
    					 {3, 4, 0x00, 0x00},
    					 {0x00, 0xFF, 0x00, 0xFF},
    					 {0xFF, 0x00, 0xFF, 0x00}
     					 };
    
    XMEM = &sxima[0][0];
    display1(2, 10, sxima[0][0],sxima[0][1], XMEM);
    }

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    30
    i don't think so. xdata is saying that it wil be stored in the outside memory of the microcontroller.
    I am working on an embedded system.

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    ERROR 104: MULTIPLE PUBLIC DEFINITIONS
    WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
    The warning is just telling you that you have defined a function that never gets called. Since it would be a waste of space to bring it along, the linker let's you know that it doesn't bother putting it in the code.

    I couldn't reproduce the error -- I'd check the linker options you have specified. (Since it's a linker error, the source code may not point to an answer.)

    Regarding the xdata and other extended keywords, I find it a good idea to use wrapper macros that are conditionally defined for the specific compiler. For example,
    Code:
    #ifdef __C51__
    #define XDATA xdata
    #else
    #define XDATA
    #endif
    
    #define XBYTE ((unsigned char volatile XDATA*) 0)
    At the very least, it informs others that your code intentionally goes nonstandard in places.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array problem
    By TomBoyRacer in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2007, 11:35 AM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Replies: 6
    Last Post: 02-15-2005, 11:20 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Need desperate help with two dimensional array problem
    By webvigator2k in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2003, 02:28 PM