I am trying to translate the follwing into C++ for the arduino

The IDE does not like my return statement which I figured as much but I may be missing something else

unsigned int computeCrc(int byteArray[], int len)
{
  long crc;
  long q;
  int c;
  int i;
  crc = 0;
  for (i = 0; i < len; i++)
  {
    c = byteArray[i];
    q = (crc ^ c) & 0x0f;
    crc = (crc >> 4) ^ (q * 0x1081);
    q = (crc ^ (c >> 4)) & 0xf;
    crc = (crc >> 4) ^ (q * 0x1081);
   }
     return new byte[] { (byte)(crc & 0xff), (byte)(crc >> 8)
   }

here is the code that works in MS Visual Studio C#

public static byte[] ComputeCRC(byte[] val)
        {
            long crc;
            long q;
            byte c;
            crc = 0;
            for (int i = 0; i < val.Length; i++)
            {
                c = val[i];
                q = (crc ^ c) & 0x0f;
                crc = (crc >> 4) ^ (q * 0x1081);
                q = (crc ^ (c >> 4)) & 0xf;
                crc = (crc >> 4) ^ (q * 0x1081);
            }
            return new byte[] { (byte)(crc & 0xff), (byte)(crc >> 8) };

        }  // End of ComputeCRC

it is based on the X^16+X^12+X^5+1
start value = 0 and key is 0x1081 or 10201 octal

any help would be appreciated
Thanks

Read this before posting a programming question

And the error message was?

unsigned int computeCrc(int byteArray[], int len)

You tell the compiler that your function returns an unsigned int.

     return new byte[] { (byte)(crc & 0xff), (byte)(crc >> 8)

Then you try to return an array.

Pointer to an array. But you are right, the OP has modified the code that used to work.

Why return a byte array instead of "composing" a 16 bit value ?

Issues with expected endianness? Arse-about-face way of doing though.

Does this look like it would work then
I cant figure out how to return a byte array since coding it like C# likes as byte functionname (arguemnts) did not work
so I changed the code to place the result into globalCRC variable instead.
I would like to pass an array of any size but have not figured out how to do that so I will track the length, I need to test it
so I am going to pass it some arrays that have the proper CRC at the end.

void ComputeCRC(byte val[32] , int len)
{
  long crc;
  long q;
  byte c;
  crc = 0;
  for (int i = 0; i < len; i++)
  {
    c = val[i];
    q = (crc ^ c) & 0x0f;
    crc = (crc >> 4) ^ (q * 0x1081);
    q = (crc ^ (c >> 4)) & 0xf;
    crc = (crc >> 4) ^ (q * 0x1081);
  }
  globalCRC[0]=crc & 0xff;
  globalCRC[1]=crc >> 8;

Probably not. C doesn't bounds-check array accesses. Why not simply return a locally-defined "unsigned int"? Using globals as a return mechanism is prehistoric.

AWOL: Probably not. C doesn't bounds-check array accesses. Why not simply return a locally-defined "unsigned int"? Using globals as a return mechanism is prehistoric.

I was trying to return a unsigned int, but not sure what the code would have looked like to make the returned int had the CRC correct. then use highbyte and lowbyte to place the 2 bytes in the array

You can't use highByte and lowByte for that.

  return (crc & 0xff) | (crc >> 8);

might do the trick, depending on endianess.