visual-studio - C++小白,今天VS2015编译一个开源项目遇到如下问题
PHPz
PHPz 2017-04-17 13:31:32
0
4
611

错误部分代码如下

static const struct ft_error ft_errors[] =
{
#include FT_ERRORS_H
};

提示错误位置在};这里

求问这是什么错误?导致的原因是什么?如何解决?

环境win10 ,Visual studio 2015 up1

PHPz
PHPz

学习是最好的投资!

reply all(4)
黄舟

#include can only appear at the beginning of the file

Peter_Zhu

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.

大家讲道理

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.

黄舟

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:

  1. http://stackoverflow.com/questions/16389126/can-the-pre-processor-directives-like-include-be-placed-only-at-the-top-of-the

  2. http://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!