Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

extern pointer C bug or not?

Is:

extern cyg_uint8 gr_data_written[];

the same as?

extern cyg_uint8 *gr_data_written;

retrieving via

{ unsigned char *dp;

dp = gr_data_written;

my ecos gcc sets dp as the pointer if gr_data_written is declared the first way and as contents if declared the second way. Should it be the same?

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The question is not clear enough.

    You'd better show a simple example.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by david_cai@Oct 24 2006, 07:16 PM

    the question is not clear enough.

    you'd better show a simple example.

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=18886)

    --- quote end ---

    --- Quote End ---

    Example:

    // in declaration file

    cyg_uint8 gr_data_written[5] = {1,2,3,4,5};

    ---

    // in this other file# ifdef FIRSTWAY

    extern cyg_uint8 gr_data_written[];# else

    extern cyg_uint8 *gr_data_written;# endif

    showme()

    {

    printf ("%x", (int) gr_data_written);

    # ifdef FIRSTWAY

    output of printf is a ptr "4A178";# else

    output of printf is the value "1";# endif

    -----------

    I thought it was supposed to be the same either way, but it wasn&#39;t.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I think it is related to declaring a pointer vs. declaring an array.

    Note, the *gr_data_written pointer is not declared anywhere nor initialized.

    Thus, the result should be undefined.

    When declaring, pointer and array are different.

    Garland

    --- Quote Start ---

    originally posted by itntest+oct 26 2006, 05:23 pm--><div class='quotetop'>quote (itntest @ oct 26 2006, 05:23 pm)</div>

    --- quote start ---

    <!--quotebegin-david_cai@Oct 24 2006, 07:16 PM

    the question is not clear enough.

    you&#39;d better show a simple example.

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=18886)

    --- quote end ---

    --- Quote End ---

    Example:

    // in declaration file

    cyg_uint8 gr_data_written[5] = {1,2,3,4,5};

    ---

    // in this other file# ifdef FIRSTWAY

    extern cyg_uint8 gr_data_written[];# else

    extern cyg_uint8 *gr_data_written;# endif

    showme()

    {

    printf ("%x", (int) gr_data_written);

    # ifdef FIRSTWAY

    output of printf is a ptr "4A178";# else

    output of printf is the value "1";# endif

    -----------

    I thought it was supposed to be the same either way, but it wasn&#39;t.

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=18938)</div>

    [/b]

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Please try the following.

    <span style="font-family:Courier">// in declaration file

    cyg_uint8 gr_data_written[5] = {1,2,3,4,5};

    cyg_uint8 *pData = gr_data_written; // initialize the pointer

    //---

    // in this other file

    extern cyg_uint8 gr_data_written[]; // good

    extern cyg_uint8 *pData ; // good

    </span>

    Good luck!

    Garland