修正錯誤我有一個.c文件和兩個頭。我不知道爲什麼會出現這些錯誤。我試圖在網絡中找到解決方案,但無法將其應用於我的代碼。錯誤而用C
Structs.h
#ifndef STRUCTS_H
#define STRUCTS_H
typedef struct stream
{
char* enc; //binary string
int pos;
}stream;
typedef struct tag
{
int tagClass;
char tagConstructed;
char tagNumber;
}tag;
#endif
Funcs.h錯誤:
Error 22 error C2143: syntax error : missing '{' before '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 15 1 asn1
Error 26 error C2143: syntax error : missing '{' before '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 36 1 asn1
Error 21 error C2143: syntax error : missing ')' before '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 15 1 asn1
Error 25 error C2143: syntax error : missing ')' before '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 36 1 asn1
Error 15 error C2061: syntax error : identifier 'isUniversal' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 3 1 asn1
Error 18 error C2061: syntax error : identifier 'isEOC' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 7 1 asn1
Error 17 error C2059: syntax error : 'type' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 3 1 asn1
Error 20 error C2059: syntax error : 'type' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 7 1 asn1
Error 16 error C2059: syntax error : ';' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 3 1 asn1
Error 19 error C2059: syntax error : ';' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 7 1 asn1
Error 24 error C2059: syntax error : ')' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 15 1 asn1
Error 28 error C2059: syntax error : ')' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 36 1 asn1
Error 23 error C2059: syntax error : '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 15 1 asn1
Error 27 error C2059: syntax error : '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 36 1 asn1
#ifndef FUNCS_H
#define FUNCS_H
#include "Structs.h"
bool isUniversal(tag curTag);
bool isEOC(tag curTag);
char getByte(stream curStream);
void parseTag(stream & str, tag & tag);
char parseLength(stream & str);
#endif
Functions.c錯誤:
Error 22 error C2143: syntax error : missing '{' before '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 15 1 asn1
Error 26 error C2143: syntax error : missing '{' before '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 36 1 asn1
Error 21 error C2143: syntax error : missing ')' before '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 15 1 asn1
Error 25 error C2143: syntax error : missing ')' before '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 36 1 asn1
Error 15 error C2061: syntax error : identifier 'isUniversal' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 3 1 asn1
Error 18 error C2061: syntax error : identifier 'isEOC' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 7 1 asn1
Error 17 error C2059: syntax error : 'type' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 3 1 asn1
Error 20 error C2059: syntax error : 'type' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 7 1 asn1
Error 16 error C2059: syntax error : ';' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 3 1 asn1
Error 19 error C2059: syntax error : ';' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 7 1 asn1
Error 24 error C2059: syntax error : ')' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 15 1 asn1
Error 28 error C2059: syntax error : ')' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 36 1 asn1
Error 23 error C2059: syntax error : '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 15 1 asn1
Error 27 error C2059: syntax error : '&' c:\users\natasha\documents\visual studio 2012\projects\asn1\asn1\functions.c 36 1 asn1
#include "Funcs.h"
bool isUniversal(tag curTag) {
return curTag.tagClass == 0x00;
}
bool isEOC(tag curTag) {
return (curTag.tagClass == 0x00) && (curTag.tagNumber == 0x00);
}
char getByte(stream curStream) {
return curStream.enc[curStream.pos];
}
void parseTag(stream & str, tag & tag)
{
char buf, tempNumber;
buf = getByte(str);
tempNumber = 0x00;
tag.tagClass = buf >> 6;
tag.tagConstructed = ((buf & 0x20) != 0);
tag.tagNumber = buf & 0x1F;
if (tag.tagNumber == 0x1F)
{
do
{
str.pos++;
buf = getByte(str);
tempNumber = (tempNumber << 7) | (buf & 0x7F);
}while(buf & 0x80);
tag.tagNumber = tempNumber;
}
}
char parseLength(stream & str) {
char buf, len;
int numberOfOctets, i;
buf = getByte(str);
len = 0x00;
numberOfOctets = 0;
if (buf < 0x80) {
len = buf; //short form
} else { //long form
numberOfOctets = buf & 0x7F;
for (i = 0; i < numberOfOctets; ++i) {
len = (len * 256) + getByte(str);
str.pos++;
}
}
return len;
}
C沒有像C++那樣的引用..'void parseLength(stream & str);'不是有效的語法(因爲'&'),你可以使用指針代替 – Dmitri
@Dmitri,謝謝!幫我應付錯誤的重要組成部分。但在與布爾線的錯誤仍然存在。我試圖添加但編譯器無法識別此頭/ –
MyName
的C舊版本沒有'bool'類型,但你可以使用一個整數類型,而不是... C99和高達你可以得到'通過包括'stdbool.h'頭bool'。 – Dmitri