Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

extern pointer C bug or not?

Altera_Forum
Honored Contributor II
1,026 Views

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?
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
280 Views

The question is not clear enough. 

You'd better show a simple example.
0 Kudos
Altera_Forum
Honored Contributor II
280 Views

 

--- 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.
0 Kudos
Altera_Forum
Honored Contributor II
280 Views

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 ---  

0 Kudos
Altera_Forum
Honored Contributor II
280 Views

Not convinced yet. 

Thoughts from anyone else?
0 Kudos
Altera_Forum
Honored Contributor II
280 Views

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
0 Kudos
Reply