Array of pointer - needs help

V

vib

Hi there,

I am stuck with the following code. It is an array of pointers, in
ADS1.2 compiler I encounter the errors, but not on other compiler. Can
someone please shade some light, please! Frankly, I can't see anything
wrong with the code, but the compiler just refuse it as I wish.

Thanks in advance

vib

--------

unsigned int myvar1=1, myvar2=2;

const * unsigned int myArrayOfPtr[] = {
(* unsigned int)&myvar1,
(* unsigned int)&myvar2,
};

-------

Error : (Serious) C2322E: Expecting <declarator> or <type> but found
'unsigned'
lcd_drv.c line 92

Error : C2285E: expected ';' or ',' - inserted ';' before '{'
lcd_drv.c line 92

Error : (Serious) C2337E: Misplaced '{' at top level - ignoring block
lcd_drv.c line 92

Error : (Serious) C2291E: <expression> expected but found 'unsigned'
lcd_drv.c line 93

Error : (Serious) C2282E: expected ')' - inserted before 'unsigned'
lcd_drv.c line 93

Error : (Serious) C2284E: expected ';' after command - inserted
before 'unsigned'
lcd_drv.c line 93

Error : (Serious) C2304E: <command> expected but found 'unsigned'
lcd_drv.c line 93

Error : C2487E: declaration with no effect
lcd_drv.c line 95

C:\_ucos251_S5L8700x\BSP_S3C2400\src\lcd_drv.c: 0 warnings, 2 errors, 6
serious errors
 
M

Mike Wahler

vib said:
Hi there,

I am stuck with the following code. It is an array of pointers, in
ADS1.2 compiler I encounter the errors, but not on other compiler. Can
someone please shade some light, please! Frankly, I can't see anything
wrong with the code, but the compiler just refuse it as I wish.

Thanks in advance

vib

--------

unsigned int myvar1=1, myvar2=2;

const * unsigned int myArrayOfPtr[] = {
(* unsigned int)&myvar1,
(* unsigned int)&myvar2,
};

const unsigned int *myArrayOfPtr[] =
{
&myvar1,
&myvar2
};

-Mike
 
M

Martin Ambuhl

vib said:
Hi there,

I am stuck with the following code. It is an array of pointers, in
ADS1.2 compiler I encounter the errors, but not on other compiler.

Then your other compiler is broken. Your code is seriously wrong.
Can
someone please shade some light, please!

Your '*'s are all in the wrong places.
unsigned int myvar1=1, myvar2=2;

const * unsigned int myArrayOfPtr[] = {
(* unsigned int)&myvar1,
(* unsigned int)&myvar2,
};

should be
const unsigned int *myArrayOfPtr[] = {
(unsigned int *)&myvar1,
(unsigned int *)&myvar2 /* losing the ',' also */
};

If you just *must* have those casts. But the presence of the casts
suggests that your code is misdesigned anyway. If myvar1 and and myvar2
are not unsigned ints, then you are probably asking for trouble later
on. If the are unsigned ints, then

const unsigned int *myArrayOfPtr[] = {&myvar1, &myvar2};
will do the job just fine.

And don't use tabs in usenet postings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top