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++
12603 Discussions

global pointer assignment error

Altera_Forum
Honored Contributor II
991 Views

Nios 5.0.1 

 

In global scope: 

 

char test[20]="teststring"; 

 

char *cp1 = &test[0]; //this works 

 

char *cp1; cp1 = &test[0]; //but this does not 

 

 

It all works inside a function, but not in global scope. 

Is this part of the anti-global variable campaign, or something I missed in my remedial C class?
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
279 Views

Because the first assignment is done at compile time, and second assignment must be done at run time i.e. generates code. This is only allowed inside a function. Too early in the morning...

0 Kudos
Reply