【问题标题】:undeclared here (not in a function) in C在 C 中未在此处声明(不在函数中)
【发布时间】:2019-10-02 04:02:24
【问题描述】:

我是 c 语言的新手,但我试图理解这个用 c 语言编写的夸克散列算法,我在编译源代码时发现了一个错误,据我了解它已经声明的 WIDTH,但为什么是它仍然错误吗?

这是源代码

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

/* uncomment to printf execution traces */
// #define DEBUG

#if   defined(UQUARK)
#define CAPACITY 16 
#define RATE      1
#define WIDTH    17
#elif defined(DQUARK)
#define CAPACITY 20
#define RATE      2
#define WIDTH    22
#endif


#define DIGEST WIDTH

typedef uint64_t u64;
typedef uint32_t u32;
typedef uint8_t   u8; 

typedef struct {
  int pos; /* number of bytes read into x from current block */
  //  u32 x[ WIDTH*8 ]; /* one bit stored in each word */
  u32 x[ WIDTH*8 ]; /* one bit stored in each word */
} hashState;


#if   defined(UQUARK)
/* 17 bytes */
u8 iv[] = {0xd8,0xda,0xca,0x44,0x41,0x4a,0x09,0x97,
       0x19,0xc8,0x0a,0xa3,0xaf,0x06,0x56,0x44,0xdb};

并显示此错误

quark.c:36:10: error : 'WIDTH' undeclared here (not in a function)
   u32 x[WIDTH*8];

【问题讨论】:

  • 只有在定义了UQUARKDQUARK 之一时才定义WIDTH。此类控制宏通常设置在命令行或 make 文件中:gcc -DUQUARK ...cl /DUQUARK ...
  • 详细说明 M.Oehm 评论。我们将需要查看包含显示的标头和您编译的确切方式的代码文件,以便帮助您了解详细信息。请发送minimal reproducible example,其中包括建筑细节。你用make工具吗?然后显示makefile。您是否使用 IDE,然后列出所有构建参数。

标签: c hash


【解决方案1】:

我猜出于某种原因,UQUARK 和 DQUARK 都没有被定义。

添加这个:

#if defined(UQUARK) && defined(DQUARK)
#error both UQUARK and DQUARK are defined
#endif

#if !defined(UQUARK) && !defined(dQUARK)
#error Neither UQUARK nor DQUARK are defined
#endif

就在下一行之前:

#if   defined(UQUARK)

如果UQUARKDQUARK 都被定义(这可能没有意义),或者UQUARKDQUARK 都没有被定义(这可能在你的情况下发生),那么编译将中止。

现在的问题是:谁定义了UQUARK 和/或DQUARK?只有你自己知道。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 2012-02-12
    • 2012-05-19
    • 2014-04-22
    • 2012-05-07
    • 2012-07-13
    相关资源
    最近更新 更多