我有两个头文件,比如h1和h2,在这两个文件中我都使用了uint8_t,在h1中我使用了uint8_t而没有使用#include <stdint.h>,它编译成功了,但是对于同样的h2,编译器给出了错误: uint8_t没有命名类型;#include "ing“stdint.h会导致编译成功。
有没有人能解释一下这种模棱两可的编译器行为。我使用的是CodeBlocks 16.01
h1:
//there is no error even if I don't include <stdint.h> and use uint8_t
#ifndef AES_ENCRYPTION_H
#define AES_ENCRYPTION_H
class AES_Encryption
{
private:
static const uint8_t S_BOX[256];
static const uint8_t R_CON[11];
uint8_t state[4][4];
unsigned short int encryptionMode;
unsigned short int Nr;
unsigned short int Nk;
public:
AES_Encryption(unsigned short int);
static uint8_t get_SBOX_value(uint8_t);
static uint8_t HEX01xARG(uint8_t);
static uint8_t HEX02xARG(uint8_t);
static uint8_t HEX03xARG(uint8_t);
void populateState(uint8_t*);
void transferCipherText(uint8_t*);
void subBytes();
void shiftRows();
void mixColumns();
void keyExpansion(const uint8_t*, uint8_t*);/*seperate thread*/
void addRoundKey(uint8_t*, int);
};
#endif // AES_ENCRYPTION_Hh2:
#ifndef AES_DECRYPTION_H
#define AES_DECRYPTION_H
class AES_Decryption
{
public:
AES_Decryption();
uint8_t x; //error in this line : uint8_t doesnot name a type; this resolves on including <stdint.h>
protected:
private:
};
#endif发布于 2018-05-20 14:23:23
在C++中,当您包含一个头文件时,它等同于简单地将头文件的源代码复制/粘贴到包含它的文件中。
例如,考虑以下文件:
某些函数.h:
int some_function();somefunction.cpp:
#include "somefunction.h"
void some_function(){ return 1+1; }编译后,编译器(或者更具体地说,预处理器)要做的第一件事就是将somefunction.cpp转换成以下代码:
int some_function();
void some_function{ return 1+1; }如您所见,某些function.h的内容被嵌入到somefunction.cpp中。
现在,为了将这个问题与您的问题联系起来,我怀疑您包含h1.h的位置如下所示:
#include <iostream>
#include "h1.h"因为h1.h的内容只是通过include指令嵌入到源文件中,所以在iostream的include指令之后(其本身可能包含stdint.h¹),h1.h的代码可以使用stdint.h中的名称。如果您在包含h2.h的地方没有首先包含stdint.h,那么您将收到您声称的错误。
而异
https://stackoverflow.com/questions/50427910
复制相似问题