Re: Passing an already declarted array of structures!



Hello again!

Okay, Here is a very watered down version of my project. The rest of code in
the watered down project does not really pertain to this issue and I am very
sure about this. So this is the meat of it!

=======================================Header
struct z{
int SCREEN; //SCREEN NUMBER
int MSG; //MESSAGE NUMBER
int VPIX_START; //VERTICAL MESSAGE START PIXEL
int HPIX_START; //HORIZONTAL MESSAGE START PIXEL
}
msgINDEX[]=
{1, 1, 0, 0,
2, 1, 10, 50};

void LCD_PAINTSCREEN (
z* pMSGINDEX); //Line 41 ?(5,6) is the z !!!!!

=======================================

=======================================.c

void LCD_PAINTSCREEN ( z* pMSGINDEX)
{
//no code
}

========================================

========================================Main.c
void main()
{
while(true)
{
LCD_PAINTSCREEN(msgINDEX ); //Calling function
}
}
===================================================

I get the following error:
"Line 41 (5,6):Expecting a , or)"

Now... the interesting part about this is that if I substitute the two "z*"
in above code by "int" , I get no errors. So at this point the error at line
41 makes no sence because if there would really be a "," or a ")" missing, I
would still get the error!!!!!

If you guys see nothing wrong with the code, then I suppose its a compiler
problem. And I will send it to them.

Oh! and by the way, yes there is a CCS site and I should consult it, but the
minimum wait time is approximately 2 days per question!!!! Sometimes I can
get 2 questions answered in this site within the hour. Alot of times I figure
that my questions are non compiler related and I feel this site is my best
option to get quick reliable help. I am sorry for the inconvenience!

Please let me know if you see nothing wrong with this code.

Any feedback is still much appreciated!

--
Best regards
Robert


"Robby" wrote:

Hello, and thanks to all.

Igor, No offence taken my freind!

Okay, let me see what I can reproduce a complete sample reproducing the
error. It will take me some time to extract a sample from the current 10,000
line C program.

I will post something later!

Talk to you soon!

--
Best regards
Robert


"Igor Tandetnik" wrote:

Robby <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hello,
Another tip on structures would greatly be appreciated!
Consider the following:

====================================================
struct S {
int x;
int y;
}y[]={1,2,3,4};

This declares an array of two elements, initializing y[0].x = 1, y[0].y
= 2, y[1].x = 3 and y[1].y = 4

//Now array of this structure is declared at the same time the
structure is declared!

//Declare a function that is supposed to take a pointer to the array
of sturctures!
void f(S* p, int size) {
for (int i = 0; i < size; ++i) {
DoSomething(p[i].x);
}
}

//Calling function
f(y, 100);

This lies to function f(), telling it that the first parameter points to
an array of 100 elements when in fact there are only 2. The result is a
buffer overrun.

I am trying to pass the already declared array of structures to the f
function by the code shown above!

I get the following error!
"Identifier is already used in this scope"

The error suggests you are trying to define a variable with the same
name twice. Nothing in the code you show would cause this, so the
problem is probably in the code you don't show. Once again, I highly
recommend posting a complete sample reproducing the problem, rather than
just bits and pieces you believe might be relevant (since you haven't
yet developed a good judgement of what might be relevant, no offense
intended).

I know if I declare the array of structures seperately it works, but
suppose one wants to declare everyting at once as done above, how
would he go about it?

The code you show looks good to me. The problem might be a limitation of
the compiler you are using. Isn't there a developer community around
this compiler (CCSC, if I'm not mistaken) you can address your questions
to? You are not using VC compiler, and this group is called vc.language
for a reason.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



.



Relevant Pages


Loading