| Author |
Message |
|
|
Posted: Aug 06, 2008 - 12:05 AM |
|

Joined: Jan 10, 2007
Posts: 816
Location: Toronto, Ontario, Canada
|
|
Hello,
I have tried this several different ways but the compiler reports "array has incomplete element type" in the header file. It is reporting that the external of the array "pr_data[]" is the problem. I am wondering if I am missing something in the way of a compilation option.
This is driving me nuts!!!
Thanks,
A |
_________________ AVR Studio 4 Ver. 4.18 684
avr-gcc Ver. 4.3.0
ISIS 7
ELECTRA
|
| |
|
|
|
|
|
Posted: Aug 06, 2008 - 12:13 AM |
|

Joined: Apr 01, 2004
Posts: 3812
Location: New Mexico
|
|
| Because you are defining pr_data to be an array of struct mess_struct in the .h file, but you did you yet define struct mess_struct. Move the definition of mess_struct to your .h file. |
_________________ Kevin Rosenberg
http://b9.com
http://kevin.hypershots.com
|
| |
|
|
|
|
|
Posted: Aug 06, 2008 - 12:23 AM |
|

Joined: Jan 10, 2007
Posts: 816
Location: Toronto, Ontario, Canada
|
|
kmr,
Thank you,
Thank you,
Thank you,
A |
_________________ AVR Studio 4 Ver. 4.18 684
avr-gcc Ver. 4.3.0
ISIS 7
ELECTRA
|
| |
|
|
|
|
|
Posted: Aug 06, 2008 - 12:57 AM |
|

Joined: Apr 01, 2004
Posts: 3812
Location: New Mexico
|
|
|
|
|
|
|
Posted: Aug 06, 2008 - 02:21 PM |
|

Joined: Jan 10, 2007
Posts: 816
Location: Toronto, Ontario, Canada
|
|
Kevin,
One thing that I do not understand. If the compiler understand the external declaration of *edit_ptr and *print_ptr, why does it not know the size if mess_struct? If you do not include the array this compiles just fine.
A |
_________________ AVR Studio 4 Ver. 4.18 684
avr-gcc Ver. 4.3.0
ISIS 7
ELECTRA
|
| |
|
|
|
|
|
Posted: Aug 06, 2008 - 05:55 PM |
|

Joined: Jun 27, 2008
Posts: 54
|
|
|
andrew99 wrote:
If the compiler understand the external declaration of *edit_ptr and *print_ptr, why does it not know the size if mess_struct?
Because edit_ptr and print_ptr are pointers and compiler knows size of a pointer. |
|
|
| |
|
|
|
|
|
Posted: Aug 06, 2008 - 06:50 PM |
|

Joined: Jan 10, 2007
Posts: 816
Location: Toronto, Ontario, Canada
|
|
innocent_bystander,
My point (no pun intended) is that the stucture was already declared as global before main(). Does a pointer not have details related to the type of opject it points to associated with it?
ie. A pointer to a long does not increment the same number of bytes as a pointer to a char.
A |
_________________ AVR Studio 4 Ver. 4.18 684
avr-gcc Ver. 4.3.0
ISIS 7
ELECTRA
|
| |
|
|
|
|
|
Posted: Aug 07, 2008 - 03:42 AM |
|

Joined: Jan 20, 2008
Posts: 210
Location: Canada
|
|
| I just tried the following code:
Code:
volatile int nSize1;
volatile int nSize2;
int main(void)
{
char* test;
nSize1 = sizeof(test);
nSize2 = sizeof(*test);
return 0;
}
Looking at the assembler output, nSize1 is assigned 2, the size of the pointer. nSize2 is assigned 1, the size of the data that is being pointed to.
I have never tried dereferencing a pointer with sizeof before, but it seems to work at least with avr-gcc. |
|
|
| |
|
|
|
|
|
Posted: Aug 07, 2008 - 04:18 AM |
|


Joined: Mar 27, 2002
Posts: 18749
Location: Lund, Sweden
|
|
|
Quote:
Because edit_ptr and print_ptr are pointers and compiler knows size of a pointer.
If you by this mean that
Code:
int i = sizeof(*ptr);
yields the size of the pointer, then you are wrong. It yields the size of the thing pointed to. Here's a little test I just did in avr-gcc (value that sizeof returns in the comments):
Code:
typedef struct
{
int i;
long l;
char c;
} struct_t;
volatile int size;
int ai[42];
struct_t as[13];
int main(void)
{
struct_t s;
size = sizeof(s); // 7 , the size of the struct
struct_t * ps;
size = sizeof(ps); // 2 , the size of the pointer
size = sizeof(*ps); // 7 , the size of the struct
size = sizeof(ai); // 84 , the size of the array
size = sizeof(ai[0]); // 2 , the size of one element in the array
size = sizeof(as); // 91 , the size of the array
size = sizeof(as[0]); // 7 , the size of one element in the array
}
|
|
|
| |
|
|
|
|
|
Posted: Aug 07, 2008 - 11:13 PM |
|

Joined: Jun 27, 2008
Posts: 54
|
|
|
JohanEkdahl wrote:
If you by this mean that
Code:
int i = sizeof(*ptr);
yields the size of the pointer, then you are wrong.
No, I meant that pointer can be used as structure member, even if structure this pointer points to is incomplete.
Code:
struct a_t;
typedef struct
{
struct a_t *pointer;
int other;
} struct_t;
extern struct a_t *pointer2;
struct_t as[13];
int main(void)
{
as[0].pointer = pointer2;
size = sizeof(as[0].pointer); // 2 , size of the pointer
}
Of course, you can not do any arithmetics with such pointer or dereference it, but can assign it and use as a struct member. |
|
|
| |
|
|
|
|
|