为什么不能将const整数用作数组的大小?

时间:2017-09-16 12:16:43

标签: c

public class PresenceMonitor {
    private volatile bool _running;
    private Timer timer;
    private readonly TimeSpan _presenceCheckInterval = TimeSpan.FromMinutes(1);

    public PresenceMonitor() {
        Tick += OnTick;
    }

    public void Start() {
        if (_running) {
            return; //already running
        }
        // Start the timer
        timer = new System.Threading.Timer(_ => {
            Tick(this, EventArgs.Empty);//rasie event
        }, null, TimeSpan.Zero, _presenceCheckInterval);
    }

    private event EventHandler Tick = delegate { };
    private async void OnTick(object sender, EventArgs args) {
        if (_running) {
            return;
        }
        _running = true;
        await DoworkAsync();
    }

    private Task DoworkAsync() {
        //...
    }
}

数组的大小必须是常量表达式。我已将#include <stdio.h> const int i=1; int a[i]; int main() { printf("Hello World"); return 0; } 声明为i,为什么还有错误?

const

为什么在函数main.c:12:5: error: variably modified 'a' at file scope int a[i]; ^ 内部移动部件:

main

感谢。

0 个答案:

没有答案