错误部分代码如下
static const struct ft_error ft_errors[] =
{
#include FT_ERRORS_H
};
提示错误位置在};
这里
求问这是什么错误?导致的原因是什么?如何解决?
环境win10 ,Visual studio 2015 up1
天蓬老师2017-04-17 13:33:32
Suppose your header file is defined as FT_ERRORS_H.h, you need to modify it to
static const struct ft_error ft_errors[] =
{
#include "FT_ERRORS_H.h"
};
That is, the header file needs to be included. When the compiler compiles, the contents in the header file will be mapped into the array.
大家讲道理2017-04-17 13:33:32
FT_ERROR_H does not look like the name of a header file, maybe you are referring to "ft/error.h"?
In addition, precompilation like #include can pass, and the text in the header file will be replaced here. But this
is not conducive to debugging. You can talk about your needs and we can do it in another way.
黄舟2017-04-17 13:33:32
The include directive must be defined in the file field (not only in the file header!), and must be defined before using any function package or variable defined in it for the first time.
See ISO/IEC 9899:1999 standard section 7.1.2:
If used, a header shall be included outside of any external declaration or definition, and it shall first be included before the first reference to any of the functions or objects it declares, or to any of the types or macros it defines.
In response to your problem, the #include directive should be removed from ft_errors:
#include FT_ERRORS_H
// I assume that FT_ERRORS_H has been correctly defined with corresponding header file name
static const struct ft_error ft_errors[] =
{
// concrete struct definition/declaration
};
Reference:
http://stackoverflow.com/questions/16389126/can-the-pre-processor-directives-like-include-be-placed-only-at-the-top-of-the
http://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf