首页
社区
课程
招聘
未解决 [求助]模板如何使用的问题
发表于: 2020-7-24 21:00 1471

未解决 [求助]模板如何使用的问题

2020-7-24 21:00
1471

完整的代码在2楼,编译无法通过。请教如何修改?

 

const int NUM_IN = 4;
const int NUM_REC = 2; // recovery

 

#define BUF_SIZE 1024

 

函数定义的地方

 

template<typename gtype, typename utype>
int test4(int NUM_IN, int *expected_bases) {
//const int NUM_IN = 10;

 

const int NUM_REC = 1; // recovery
const int LOW_EXPONENT = 1;

 

u8 data[NUM_IN + NUM_REC][BUF_SIZE];

 

int high_exponent = LOW_EXPONENT + NUM_REC - 1;

 

for (int i = 0; i < NUM_IN; i++) {
// fill with zeros,
for (int k = 0; k < BUF_SIZE; k++) {
data[i][k] = (u8)0;
}
// EXCEPT write a (little endian) 1 in a different place for each file
// In the i-th file, it is written into the i-th location
data[i][sizeof(utype)*i] = (u8) 1;
}
// zero recovery
for (int j = 0; j < NUM_REC; j++) {
for (int k = 0; k < BUF_SIZE; k++) {
data[NUM_IN + j][k] = (u8)0;
}
}

 

ReedSolomon<gtype> rs_creator;

 

//cout << "creator.setinput" << NUM_IN << endl;
if (!rs_creator.SetInput(NUM_IN, cout, cerr)) {
cerr << "rs_creator.SetInput returned false";
return 1;
}
//cout << "creator.setoutput" << LOW_EXPONENT << " " << high_exponent << endl;
if (!rs_creator.SetOutput(false, LOW_EXPONENT, high_exponent)) {
cerr << "rs_creator.SetOutput returned false";
return 1;
}
//cout << "creator.compute" << endl;
if (!rs_creator.Compute(nlSilent, cout, cerr)) {
cerr << "rs_creator.Compute returned false";
return 1;
}

 

for (int i = 0; i < NUM_IN; i++) {
for (int j = 0; j < NUM_REC; j++) {
//cout << "creator.process " << BUF_SIZE << " " << i << " " << j <<
endl;
rs_creator.Process(BUF_SIZE, i, &(data[i][0]), j, &(data[NUM_IN + j][0])
);
}
}

 

// The recovery file has exponent 1 and should
// contain each base to the power 1.
for (int i = 0; i < NUM_IN; i++) {
// read little-endian value
utype v = 0;
for (int byte_index = 0; byte_index < sizeof(utype); byte_index++) {
u8 byte = data[NUM_IN+0][sizeof(utype)i + byte_index];
v |= (((utype)byte) << (byte_index
8));
}
int base = v;
if (base != expected_bases[i]) {
cerr << "base at location " << i << " did not match expected." << endl;
cerr << " base = " << base << endl;
cerr << " expected = " << expected_bases[i] << endl;
return 1;
}
}
return 0;
}

 

====================

 

在下面的函数中被用到

 

int expected_bases16[10] = {2, 4, 16, 128, 256, 2048, 8192, 16384, 4107,
32856};
if (test4<Galois16,u16>(10, expected_bases16)) {
cerr << "FAILED: test4(16)" << endl;
return 1;
}


[课程]FART 脱壳王!加量不加价!FART作者讲授!

最后于 2020-7-25 11:14 被limee编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 1540
活跃值: (2807)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
// 下面的函数怎么改成不用模板的调用

#include <iostream>


const int NUM_IN  = 4;
const int NUM_REC = 2;  // recovery

#define BUF_SIZE 1024


// 函数定义的地方

template<typename gtype, typename utype>
int test4(int NUM_IN, int *expected_bases) {
  //const int NUM_IN  = 10;

  const int NUM_REC = 1;  // recovery
  const int LOW_EXPONENT = 1;

  u8 data[NUM_IN + NUM_REC][BUF_SIZE];

  int high_exponent = LOW_EXPONENT + NUM_REC - 1;

  for (int i = 0; i < NUM_IN; i++) {
    // fill with zeros,
    for (int k = 0; k < BUF_SIZE; k++) {
      data[i][k] = (u8)0;
    }
    // EXCEPT write a (little endian) 1 in a different place for each file
    // In the i-th file, it is written into the i-th location
    data[i][sizeof(utype)*i] = (u8) 1;
  }
  // zero recovery
  for (int j = 0; j < NUM_REC; j++) {
    for (int k = 0; k < BUF_SIZE; k++) {
      data[NUM_IN + j][k] = (u8)0;
    }
  }


  ReedSolomon<gtype> rs_creator;

  //cout << "creator.setinput" << NUM_IN << endl;
  if (!rs_creator.SetInput(NUM_IN, cout, cerr)) {
    cerr << "rs_creator.SetInput returned false";
    return 1;
  }
  //cout << "creator.setoutput" << LOW_EXPONENT << " " << high_exponent << endl;
  if (!rs_creator.SetOutput(false, LOW_EXPONENT, high_exponent)) {
    cerr << "rs_creator.SetOutput returned false";
    return 1;
  }
  //cout << "creator.compute" << endl;
  if (!rs_creator.Compute(nlSilent, cout, cerr)) {
    cerr << "rs_creator.Compute returned false";
    return 1;
  }

  for (int i = 0; i < NUM_IN; i++) {
    for (int j = 0; j < NUM_REC; j++) {
       //cout << "creator.process " << BUF_SIZE << " " << i << " " << j << endl;
       rs_creator.Process(BUF_SIZE, i, &(data[i][0]), j, &(data[NUM_IN + j][0]));
    }
  }


  // The recovery file has exponent 1 and should
  // contain each base to the power 1.
  for (int i = 0; i < NUM_IN; i++) {
    // read little-endian value
    utype v = 0;
    for (int byte_index = 0; byte_index < sizeof(utype); byte_index++) {
      u8 byte = data[NUM_IN+0][sizeof(utype)*i + byte_index];
      v |= (((utype)byte) << (byte_index*8));
    }
    int base = v;
    if (base != expected_bases[i]) {
      cerr << "base at location " << i << " did not match expected." << endl;
      cerr << "   base     = " << base << endl;
      cerr << "   expected = " << expected_bases[i] << endl;
      return 1;
    }
  }
  return 0;
}

////====================

//在下面的函数中被用到

using namespace std;

int main()
{
  int expected_bases16[10] = {2, 4, 16, 128, 256, 2048, 8192, 16384, 4107, 32856};
  if (test4<Galois16,u16>(10, expected_bases16)) {
    cout << "FAILED: test4(16)" << endl;
    return 1;
  }
}
2020-7-24 23:05
0
游客
登录 | 注册 方可回帖
返回
//