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