Function parameters

Hello everybody :slight_smile: , I want to create a function that returns an array parity by xor, my code doesn't work

boolean d[16] = {0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0};
boolean S;

void Xor(boolean *x, boolean T[]) {
  int i = 1;
  *x = T[0];
  for (i = 1; i < sizeof(T); i++) {
    *x =  T[i] xor * x;
  }
}
void setup() {
  Serial.begin(9600);// put your setup code here, to run once:
}

void loop() {
  /* int i= 1;
    S=d[0];
    while(i<sizeof(d)){
     S=S xor d[i];
     i++;
     }*/
  Xor(&S, d);
  Serial.print(S);
  delay(5000);
}

I would write it this way:

boolean testArray[16] = {0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0};

boolean parity(boolean *array, size_t len) {
  boolean result = false;
  for (size_t idx = 0; idx < len; idx++) {
    result ^= array[idx];
  }
  return result;
}

void setup() {
  Serial.begin(115200);
  boolean arrayParity = parity(testArray, sizeof(testArray));
  Serial.print(F("parity = "));
  Serial.println(arrayParity);
}
void loop() {}
parity = 1

Yes, it works thank you very much :slight_smile:

honestly It's not easy for me to handele this part, I tried to creat another function like this

boolean Affect(boolean *d[],int *pX[]){
  boolean Xd[sizeof(pX)];
  for(int i=0; i<sizeof(pX);i++){
    Xd[i]= d[*pX[i]];
    }
    return Xd;
  }

but it gives me this error
cannot convert 'boolean ()[44] {aka bool ()[44]}' to 'boolean** {aka bool**}' for argument '1' to 'boolean Affect(boolean**, int**)'

medeloualidi:
honestly It's not easy for me to handele this part, I tried to creat another function like this

boolean Affect(boolean *d[],int *pX[]){

boolean Xd[sizeof(pX)];
  for(int i=0; i<sizeof(pX);i++){
    Xd[i]= d[*pX[i]];
    }
    return Xd;
  }




but it gives me this error 
cannot convert 'boolean (*)[44] {aka bool (*)[44]}' to 'boolean** {aka bool**}' for argument '1' to 'boolean Affect(boolean**, int**)'

I'd look at what is being passed to the function. Compiler is complaining that it isn't what the function expects.

sizeof in that context will NOT tell you the length of the array. It will tell you how many bytes of memory the pointer to the array occupies. There is not way to determine the amount of memory allocated to an array. If your function needs the array length you must pass it as an argument.

All things, BTW, that can be easily determined by writing a few simple lines of code to TEST what your code is actually doing, as opposed to what you imagine it's doing...

Regards,
Ray L.