该行的含义:(void)(pointer);

时间:2019-04-13 07:15:44

标签: c embedded

我在TSS项目https://github.com/tpm2-software/tpm2-tss中阅读了此代码 这是他们的功能

/*
  Let's simply represent this entire problem space differently. 
  Let's reconceive homogeneous, higher-order, JS arrays as two-
  dimensional, algebraic arrays instead of JS arrays, since JS 
  is not natively well-suited for this. 

  First, a few utility functions for handling arrays...
*/

// calculate and return the sums of all the desired subarrays - 
// relies on functions that treat JS arrays *differently*;
// current implementations assumes that square subarrays of shape 
// {size x size} are desired
function calcSubSums(arr, size) {
  var sums = new Array();
  console.log(arr.length);
  for (var i = 0; i < arr.length - size + 1; i++) {
    for (var j = 0; j < arr[i].length - size + 1; j++) {
      sums.push(reduce(ravel(getSubArray(arr, [i, j], size))));
    }
  }
  return sums;
};

// for an array, arr, return subarray that starts at the top-left-
// corner indexes tlc (top-row-index, left-column-index) for an 
// extent of size on each dimension
function getSubArray(arr, tlc, size) {
  var a = new Array();
  for (var i = tlc[0]; i < size + tlc[0]; i++) {
    var b = new Array();
    for (var j = tlc[0]; j < size + tlc[0]; j++) {
      //if ((i==tlc[0]) || (i == tlc[0]+size)-1)
      b.push(arr[i][j]);
      //}
      if (i == tlc[0] + 1) {
        //b[i][tlc[1]] = 0;
        b[i].pop();
        b[i].shift();
        //b[i][tlc[size + tlc[1]]] = 0;
      }
      //console.log(b);
    }
    a.push(b);
  }
  console.log(a);
  return a;
};

// convert a higher dimensional array into one-dimensional array 
// that contains all of its elements, unpacking from top-to-bottom, 
// left-to-right
function ravel(arr, flat) {
  // If flat - accumulator array - not yet defined, create it.
  if ('undefined' == typeof flat) flat = new Array();
  // If arg is an array, iterate over the elements in index order.
  if (isArray(arr)) {
    // Call self recursively to get elements or process next, 
    // outermost level of nesting.
    for (var i = 0; i < arr.length; i++) {
      ravel(arr[i], flat);
    }
  }
  // Otherwise, just add simple element to accumulator.
  else flat.push(arr);
  // Return accumulated values.
  return flat;
};

// return a Boolean indicator of whether the argument is a JS array
function isArray(a) {
  if ('undefined' == typeof a) {
    return false
  };
  return -1 != a.constructor.toString().indexOf('Array');
};

// place the operator {op} between the elements of a and evaluate the 
// entire, resulting expression
function reduce(a, op) {
  // Set default op (add/concatenate), if not given.
  //console.log(a);
  if ('undefined' == typeof op) op = '+';
  // Initialize command to evaluate.
  var cmd = '';
  // Compose command string - concatenate each element with op.
  for (var i = 0; i < a.length; i++) {
    cmd += a[i] + op;
  }
  // Remove, extraneous, trailing instance of op and return evaluation.
  //console.log(cmd.length);
  //console.log(op.length);
  return eval(cmd.substring(0, cmd.length - op.length));
};

// now let's test it...
window.onload = function() {
  // declare the test array
  var array = [
    [0, 0, 0, 0, 0, 0],
    [5, 5, 5, 0, 0, 0],
    [10, 10, 10, 0, 0, 0],
    [0, 0, 0, 0, 0, 0],
    [5, 5, 5, 0, 0, 0],
    [10, 10, 10, 0, 0, 0]
  ];
  // calculate all of the sums of 3x3 subset arrays of our test array 
  // and write the totals to the console
  console.log(calcSubSums(array, 3));
};

我无法理解语法“(void)(sysContext);”含义。请告诉我这是什么意思,或者让我用关键字搜索一下。 谢谢您,我的英语不好对不起。

0 个答案:

没有答案