0

The array at line 10 pr[] has no errors but the error at line 20 th[] throws an error. it works when i declare tr at the beginning of the code but fails to compile when i want to declare it in the middle of the code.

  #include<reg51.h>
unsigned int i,j,dc;
unsigned int pwr[]={0x00,0x01,0x02,0x03,0x04};
unsigned int *ch;
void main(void)
{
j=0;    
while(1)
{
unsigned int pr[5]={0x00,0x01,0x02,0x03,0x04};
ch=&pr[2];
i=0;
dc=1000;
IE=0x82;    
TMOD=0x01;
TL0=0x18;
TH0=0xfc;
TR0=1;
while(dc!=0);
unsigned int tr[5]={0x00,0x01,0x02,0x03,0x04};
dc=1000;

1 Answers1

0

In the old version of C called "C90" or sometimes "ANSI-C", you couldn't declare variables anywhere, but only in the beginning of a block. This was corrected in the year 1999, so you must be using a 20+ years old compiler, or have it stuck in C90 mode. Consider using standard C instead of whatever you are currently using. C90 and 8051 are both outdated technologies.

Lundin
  • 195,001
  • 40
  • 254
  • 396