Casting to an array of structures.

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not using the GCC compiler, so ignore this if you care to. However, help would be appreciated.

Here is the problem:

I define the following structure in a header file:

typedef struct
{
   UInt8_T name[20];
   UInt8_T farmID;
   UInt8_T fieldID;
} FARM_NAME_SJ;

I then define a pointer to an array of those structures in the C file:

huge FARM_NAME_SJ  (*FarmNameData)[];

I want to set FarmNameData to point to (LOW_SECTOR + 2). I have only been able to do this by casting a constant to a pointer to a structure. The code works, but gives me an error code.

This is the code:

FarmNameData = (huge FARM_NAME_SJ *)(LOW_SECTOR + 2);

This is the error:

   635:       FarmNameData = (huge FARM_NAME_SJ *)(LOW_SECTOR + 2);
W 165: operands of '=' are incompatible: pointer vs. pointer to array

How do I cast a constant to a pointer to an array of structures?

(Tasking compiler for the ST10F276)

Thanks if you can help,

Some Guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you want an array of structures, or an array of pointers to the structures?

As it is now

huge FARM_NAME_SJ  (*FarmNameData)[];

declares an array of pointers to the structure.

And your problem line is assigning a pointer to the structure itself (which would be array index 0, if it was an array of structures)

So, if you want an array of structures, tehn you need to declare your pointer as

huge FARM_NAME_SJ  *FarmNameData;

and then your assignment will be correct.

If what you have is an array of pointers to structures then you have th change your assignment line to

FarmNameData = (huge FARM_NAME_SJ **)(LOW_SECTOR + 2);

You obviously were aware that this is an off topiic post, not related to GCC, or AVR for that matter... you should have posted this in the "off-topic" forum. Please abide by the rules of the forum.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Glitch,

Problem solved.

Some Guy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

[Moderator Note: moving thread from AVR GCC Forum to AVR Forum]