Array of pointer - needs help

Discussion in 'C Programming' started by vib, Oct 7, 2005.

  1. vib

    vib Guest

    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
    vib, Oct 7, 2005
    #1
    1. Advertising

  2. vib

    Mike Wahler Guest

    "vib" <> wrote in message
    news:...
    > 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
    Mike Wahler, Oct 7, 2005
    #2
    1. Advertising

  3. vib

    vib Guest

    Mike Wahler wrote:
    > const unsigned int *myArrayOfPtr[] =
    > {
    > &myvar1,
    > &myvar2
    > };
    >
    > -Mike


    Haha! terrible mistake of mine.

    Thanks Mike
    vib, Oct 7, 2005
    #3
  4. vib wrote:
    > 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.
    Martin Ambuhl, Oct 7, 2005
    #4
  5. vib

    vib Guest

    Hi Martin,
    Thanks for the advice.
    vib, Oct 7, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sangeetha

    Array of pointer Vs Pointer to Array

    sangeetha, Oct 8, 2004, in forum: C Programming
    Replies:
    9
    Views:
    337
    Tim Rentsch
    Oct 9, 2004
  2. erfan

    Array of pointer and pointer of array

    erfan, Jan 28, 2008, in forum: C Programming
    Replies:
    6
    Views:
    663
    Martin Ambuhl
    Jan 28, 2008
  3. RSL
    Replies:
    14
    Views:
    3,217
  4. Hansen
    Replies:
    3
    Views:
    1,080
    rep_movsd
    Apr 24, 2010
  5. , India

    pointer to an array vs pointer to pointer

    , India, Sep 20, 2011, in forum: C Programming
    Replies:
    5
    Views:
    439
    James Kuyper
    Sep 23, 2011
Loading...

Share This Page