Error: variably modified ‘* *’ at file scope
Cause of error
Read only type used in array declaration.
This error is caused by the use of code similar to the following
const int length = 256;
char buffer[length] = {0};
In C language, const is not a real constant, its meaning is only read-only. The object declared with const is a runtime object and cannot be used as the initial value of a quantity, the length of an array, the value of a case, or in the case of a type. for example
//Error message in the comment
const int length = 256;
char buzzer[length]; //error: variably modified ‘buffer’ at file scope
int i = length; //error: initializer element is not constant
switch (x) {
case length: //error: case label does not reduce to an integer constant
/* code */
break;
default:
break;
}
The solution is to use the macro definition instead of the read-only type const
//how to solve this error
#define LENGTH 256
char buzzer[LENGTH]; //error: variably modified ‘buffer’ at file scope
int i = LENGTH; //error: initializer element is not constant
switch (x) {
case length: //error: case label does not reduce to an integer constant
/* code */
break;
default:
break;
#The difference between define and const
the type modified by const takes up space in memory, while # define does not. # define only replaces the corresponding part of the source file to be compiled with string before compilation. For example, the previous code will be preprocessed to
char buzzer[256];
int i = 256;
switch (x) {
case 256:
/* code */
break;
default:
break;
Read More:
- Read and write BMP image with Pure C language
- [Solved] Internal error XFS_WANT_CORRUPTED_GOTO at line 1635 of file fs/xfs/libxfs/xfs_alloc.c.
- The resolution of Ubuntu 16.04 screen can’t be modified and the solution of circulating login
- Solved: could not find the task ‘G + + build active file, leetcode algorithm ACM compilation and debugging
- [Solved] ubuntu makefile Cross-compilation error: file not recognized: file format not recognized
- [Solved] error: ‘QStringLiteral’ was not declared in this scope
- [Solved] Linux C++ warning: ISO C++ forbids converting a string constant to ‘char*‘ [-Wwrite-strings]
- Fastplanner compilation error: Could not find a package configuration file provided by “cmake_modules”
- Debian9 g++ Compile Error: error: ‘EDOM’ was not declared in this scope
- C# WinForm gets the storage path of the selected file
- Chinese garbled problem when running. C file in Linux
- Sublime text 3 compiles and executes C/C++ programs directly
- Ubuntu18.04 Compile A40i SDK Error: misc/create_inode.c:395:18: error: conflicting types for ‘copy_file_range‘
- [Solved] Ubuntu Eclipse C/C++ Error: launch failed.binary not found
- MAC: Clion configure C compiler Error: The C compiler identification is unknown
- [Solved] xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory #include <expat.h>
- The upgrade of Ubuntu results in an error in the compilation of Android Jack [Two Method to Solve]
- Error: loading shared libraries: cannot open shared object file: No such file or directory
- [Solved] ××: error while loading shared libraries: ××.so.19: cannot open shared object file: No such file or directory
- [Solved] Python Import mmcv Warning: ImportError: libGL.so.1: cannot open shared object file: No such file or directory