CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pointer to array pointer to structures - compile error help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
c_user



Joined: 19 May 2010
Posts: 9

View user's profile Send private message

Pointer to array pointer to structures - compile error help
PostPosted: Sat Jun 12, 2010 3:55 pm     Reply with quote

I have the following structure:

Code:
typedef struct font_struct
         {
            int16 font_length;
            int16 font_width;
         } font_select;



I then add an array of pointers to this structure, which compiles correctly:

Code:
font_select    *screen_ptr[3];


Now, I want to add a point to this array of pointers, and am using the following construction:

Code:
font_select   (*(*scr_ptr)[]);


The compiler issues an error report:

Code:
Executing: "C:\Program Files\PICC\Ccsc.exe" +FH "FT430.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 58 "FT430.c" Line 72(17,18): Expecting a close paren
*** Error 43 "FT430.c" Line 72(19,20): Expecting a declaration
*** Error 48 "FT430.c" Line 72(21,28): Expecting a (
*** Error 43 "FT430.c" Line 72(29,30): Expecting a declaration
*** Error 43 "FT430.c" Line 72(30,31): Expecting a declaration
*** Error 43 "FT430.c" Line 72(31,32): Expecting a declaration
*** Error 12 "FT430.c" Line 79(10,17): Undefined identifier   scr_ptr
      7 Errors,  0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Sat Jun 12 14:41:59 2010



What am I doing wrong?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 12, 2010 11:40 pm     Reply with quote

The method used in the test program shown below appears to work.

Here's the program output (in MPLAB simulator):
Quote:

Pointers to structures:
0005
0009
000d
Pointer to array of pointers:
0011

.Sym file:
Quote:

005-010 fs
011-016 screen_ptr
017-018 scr_ptr

Test program. Compiled with vs. 4.107:
Code:

#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

typedef struct font_struct
{
int16 font_length;
int16 font_width;
}font_select, *p_fs;

// Declare an array of 3 of the above structures.
font_select fs[3];

// Declare an array of pointers to the 3 structures,
// and initialize it the start address of each
// structure.
p_fs screen_ptr[3] = {
   &fs[0].font_length,
   &fs[1].font_length,
   &fs[2].font_length
}; 

// Declare a pointer to the array of pointers above
// and initialize it.
p_fs *scr_ptr = screen_ptr;   

//======================================
void main(void)
{
int8 i;

printf("Pointers to structures: \r");
for(i=0; i < 3; i++)
    printf("%lx \r", (int16)screen_ptr[i]);

printf("Pointer to array of pointers: \r");
    printf("%lx \r", (int16)scr_ptr);

while(1);
}
 
c_user



Joined: 19 May 2010
Posts: 9

View user's profile Send private message

PostPosted: Sun Jun 13, 2010 10:48 pm     Reply with quote

Thanks for giving me a solution. I see why it works. But I am still curious whether my C declaration was wrong, or whether the compiler can't handle it. If you know, I'd appreciate hearing your analysis.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group