【问题标题】:Is it not possible to define and declare array in the middle of a code? [duplicate]不能在代码中间定义和声明数组吗? [复制]
【发布时间】:2020-09-30 18:21:34
【问题描述】:

第 10 行 pr[] 的数组没有错误,但第 20 行 th[] 的错误会引发错误。 当我在代码的开头声明 tr 时它可以工作,但是当我想在代码中间声明它时编译失败。

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

【问题讨论】:

    标签: c embedded keil 8051


    【解决方案1】:

    在称为“C90”或有时称为“ANSI-C”的旧版 C 中,您不能在任何地方声明变量,只能在块的开头声明。这在 1999 年得到了纠正,因此您必须使用 20 多年的编译器,或者让它停留在 C90 模式。考虑使用标准 C 而不是您当前使用的任何内容。 C90 和 8051 都是过时的技术。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 2013-02-16
      • 2020-10-23
      • 2019-02-09
      • 1970-01-01
      • 2021-02-11
      • 2011-01-09
      相关资源
      最近更新 更多