2013-04-18 2 views
0

우분투 가상 환경에서 터미널을 사용하여 Linux를 처음 사용합니다. 나는 무엇이 왜 이러한 오류가 발생하는지 파악할 수 없으며, 누락 된 ''와 일치하지 않는 것처럼 보입니다. 또는 #define 충돌. 나는 키 문제는 인덱스 키를 구성지도의 선언과 초기화에 생각지도 유형을 사용하면 gcc 오류가 발생합니다 : 'for'앞에 부적합 ID가 있어야합니다.

my_predictor.h:82:42: error: template argument 2 is invalid 
my_predictor.h:82:42: error: template argument 4 is invalid 
my_predictor.h:84:9: error: expected unqualified-id before ‘for’ 
my_predictor.h:84:23: error: ‘g’ does not name a type 
my_predictor.h:84:44: error: ‘g’ does not name a type 
my_predictor.h:91:42: error: template argument 2 is invalid 
my_predictor.h:91:42: error: template argument 4 is invalid 
my_predictor.h:93:9: error: expected unqualified-id before ‘for’ 
my_predictor.h:93:23: error: ‘f’ does not name a type 
my_predictor.h:93:39: error: ‘f’ does not name a type 
my_predictor.h: In member function ‘virtual branch_update* local_predictor::predict(branch_info&)’: 
my_predictor.h:107:57: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:111:40: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h: In member function ‘virtual void local_predictor::update(branch_update*, bool, unsigned int)’: 
my_predictor.h:121:62: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:124:46: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:125:33: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:127:41: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:128:29: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:131:33: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:132:30: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:135:33: error: invalid types ‘int[int]’ for array subscript 
my_predictor.h:136:30: error: invalid types ‘int[int]’ for array subscript 

한 다음 A A 비트 세트 객체 인 : 여기

내가 GCC 컴파일러에서 얻을 오류입니다 비트 문자열. 그것은 array [] 연산 (cplusplus.com/reference/map 사이트에서 찾은 것으로부터 유효하다고 가정 됨)과 함께 나중의 오류를 만드는 것으로 보입니다.

1:// my_predictor.h 
// This file contains a sample gshare_predictor class. 
// It is a simple 32,768-entry gshare with a history length of 15. 

5:#include <bitset> 
#include <map> 
7:using namespace std; 

64:class local_predictor : public branch_predictor { 
65:public: 
#define LHBITLEN 10 
#define PREDCNTR 2 
#define LOCHISTTABLERNG 4096 
#define LOCPREDRNG 1024 
70:  local_update u; 
     branch_info bcopy; 

     // otherwise ints, where each will be multiplied by 10, then add 1 if taken/true. Initial test case to change if 10 bits long already 

75:  // ?correct location? Bit array of length 10 for local history table value entries 
     bitset<LHBITLEN> lhthistval; 
     bitset<PREDCNTR> lpcounter; 

     // initialize to 0's 
80:  // lhthistval.reset(); 

     std::map<int, (bitset<LHBITLEN>) > lochisttab; 
     //map<int, (bitset<10>) > lht; 
     for (int g=0; g < LOCHISTTABLERNG; g++) { 
85:   //const int j = g; 
      lochisttab[g] = lhthistval.reset(); 
      //lht.insert(pair<int, (bitset<LHBITLEN>)>(j, lhthistval.reset())); 
     } 

90: 
    std::map<int, (bitset<PREDCNTR>) > locprediction; 
    //map<int, (bitset<2>) > locpredict; 
    for (int f=0; f < LOCPREDRNG; f++) { 
     //const int j = f; 
95:  //locpredict.insert(pair<int, (bitset<PREDCNTR>)>(j,lpcounter.reset())); 
     locprediction[f] = lpcounter.reset(); 
    } 


100: local_predictor (void) { 
    } 

    branch_update *predict (branch_info & b) { 
     bcopy = b; 
105:  // address for locpredict based on value by modulus (remainder) of branch address divide by 4096 
     int braddr = static_cast<int>(b.address % LOCHISTTABLERNG); 
     bitset<LHBITLEN> address = lochisttab[braddr]; 
     // safe and compiler allow since it is only 10 bits long max? 
     int indx = static_cast<int>(address.to_ulong()); 
110:  // use the MSB or Pos 1 in 2 bit array to set boolean Take/Don't 
     bool take = locprediction[indx].test(1); 
     u.direction_prediction (take); 
     u.target_prediction (0); 
     return &u; 
115: } 

    void update (branch_update *u, bool taken, unsigned int target) { 

     if (bcopy.br_flags & BR_CONDITIONAL) { 
120:   int lhtaddress = bcopy.address % LOCHISTTABLERNG; 
      bitset<LHBITLEN> addr = lochisttab[lhtaddress]; 
      int indx = static_cast<int>(addr.to_ulong()); 
      for (int i=1; i < LHBITLEN; i++) { 
       bool prval = lochisttab[lhtaddress].test(i-1); 
125:    lochisttab[lhtaddress].set(i,prval); 
      } 
      bool prev = locprediction[indx].test(0); 
      locprediction[indx].set(1,prev); 

130:   if (taken) { 
       lochisttab[lhtaddress].set(0); 
       locprediction[indx].set(0); 
      } 
      else { 
135:    lochisttab[lhtaddress].reset(0); 
       locprediction[indx].reset(0); 
      } 
     } 
    } 

}; 

편집 :

여기 내 코드입니다 내가 원래지도 선언에 대한 비트 세트 인수 주위에 괄호 없었다. 컴파일러는 "for 'before for unqualified-id'의 첫 번째 오류를 제공했습니다. 템플릿 인수 오류는 괄호에서 나온 것입니다 (하지만 결국 비트 셋 데이터 유형을 잠재적으로 이해했기 때문에 결과라고 생각했습니다).

+0

당신은 괄호 유형을 넣을 수 없습니다. – leemes

+0

당신은 어떤 함수 밖에서도 for 문을 갖고있는 것처럼 보입니다. –

+0

"오류 : 예상 unqualified-id before 'for'"오류가 발생하는 것에 실제로 응답하여 괄호를 추가했습니다. parantheses는 잘못된 인수의 새로운 오류를 만들었습니다. –

답변

1

라인 82에있는 (bitset<LHBITLEN>) 주위의 위조 된 괄호가 문제라고 생각합니다 - 아마도 컴파일러가 유형 매개 변수가 아닌 템플릿 값 매개 변수로 구문 분석하려고 시도한 다음 복구하려고 시도 할 때 혼란 스러울 수 있습니다 .

이와 같은 오류가 자주 발생하는 경우가 많으므로 첫 번째 오류 만 관련성이 있으며 문제가 무엇인지 알려줍니다. 이후의 것들은 컴파일러가 의미있는 문맥을 복구하려고 시도 할 때 너무 많은 토큰을 던져서 계속해서보고있는 것에 혼란을 야기하기 때문입니다. 그것은 아마도 >;을 멀리 던져 버리고는 아직도 이것은 당신이 필요로하는 구문이다 for

+0

이제 g ++에 첫 번째 오류가 발생한 후 중지하도록 알려줄 수 있습니까? 때로는 특히 메타 타입, sfinae, enable_if 등을 다루는 경우 컴파일러 메시지가 약 50 줄로 끝나고 끝이 보이지 않는 경우가 있습니다 ... – leemes

+0

고마워요. 그리고 저는 ID를 둘러싼 오류를 처음으로 얻은 후 parantheses를 추가 한 것을 반영하여 편집했습니다. '에 대한'. 다른 오류 "error : 'g'는 형식을 지정하지 않습니다."또한 원래 그대로있었습니다. 그러나 "int [int]"오류가 발생하지 않았습니다. –

0

를 볼 때 템플릿 매개 변수 목록을 구문 분석하려고 생각 :

`map<int, bitset<10> > intBitsetMap; //Note the space between the two: > >` 
+0

원래는 >>> 사이에 공백이 있었고 #define을 숫자 값으로 사용했습니다. #define 변수를 실제 숫자로 대체 할 때 의미가 있습니까? –

관련 문제