im retarded

Why in the hell am I getting this warning in C?

On a further note, I read you are not meant to use pointers and dynamic memory. If I was to get no memory leaks in valgrind would it be alright to throw into an embedded system?

Beware Cat Shirt $21.68

Rise, Grind, Banana Find Shirt $21.68

Beware Cat Shirt $21.68

  1. 1 month ago
    Anonymous

    You can't use array notation like that buddy.
    The compiler knows that A is a pointer to a pointer to a double, it doesn't know rows and cols, you have to do the pointer arithmetic yourself buddy.

    • 1 month ago
      Anonymous

      yeah, you're dereferencing the value stored at A[i]

    • 1 month ago
      Anonymous

      ahhh thats very interesting.

      Do you know any search terms I could hunt for? Learning that would be useful.

    • 1 month ago
      Anonymous

      > pointer arithmetic
      It's the same thing?
      M[A][B] == (*(M + A * sizeof(type*~~ + B * sizeof(type)

      Is there a reason you're using ** instead of [][] or even just a flat array

      > [][]
      please stop using C

      • 1 month ago
        Anonymous

        Black person no. It's an array of pointers. Not an array of arrays of values.

        • 1 month ago
          Anonymous

          > array of pointers
          i.e pointer to pointer (both can be arrays if the memory is contiguous), therefore the same thing
          ptr points to [->ptr1<-, ptr2, ptr3, ptr4, ptr5]
          ptr[1-5] points to [->data1<-, data2, data3, data4, data5] (pointer arithmetic permits to access the others)

          >why doesn't the compiler do what I think it should?
          >read: how do I tell the computer what I want to do, but don't give me an actual answer
          Ok, so store it as a flat array moron.
          If you want to be verbose then just use an array of arrays
          >please stop using C
          You suck at programming. I was starting on your level and then suggesting the improvement to help explain in moron terms how to fix it.

          not OP genius

      • 1 month ago
        Anonymous

        >why doesn't the compiler do what I think it should?
        >read: how do I tell the computer what I want to do, but don't give me an actual answer
        Ok, so store it as a flat array moron.
        If you want to be verbose then just use an array of arrays
        >please stop using C
        You suck at programming. I was starting on your level and then suggesting the improvement to help explain in moron terms how to fix it.

        • 1 month ago
          Anonymous

          moron terms is appreciated thank you

          • 1 month ago
            Anonymous

            Like the other anon

            >array of arrays
            Don't make it hard on yourself. Make the number of cels rows * columns, then do the math to get the right offset into it.

            said, just do this.
            Make a struct Matrix with cols, rows, and just use a for loop

  2. 1 month ago
    Anonymous

    not to use pointers and dynamic memory in embedded systems*

  3. 1 month ago
    Anonymous

    Is there a reason you're using ** instead of [][] or even just a flat array

  4. 1 month ago
    Anonymous
    • 1 month ago
      Anonymous

      Wait what, why sizeof(int*)? Isn't this supposed to be a matrix of doubles?

      • 1 month ago
        Anonymous

        Im moronic, thank you

    • 1 month ago
      Anonymous

      >using double pointers for 2d array
      stop being moronic. use a flat array + macro/function to do the access calculations.
      either that or use the Variably Modified Type feature and get the compiler to do the access calculations.

  5. 1 month ago
    Anonymous

    >array of arrays
    Don't make it hard on yourself. Make the number of cels rows * columns, then do the math to get the right offset into it.

  6. 1 month ago
    Anonymous

    If A is double**, then this means you must dereference and offset two pointers to access any value inside it.
    If A is double*, then you only have to dereference and offset once to access any value.
    double *A = malloc(sizeof(double)*rows*cols);
    Is what you want, then to access you use: A[y*rows+x]

    Why does clang give you the undefined pointer dereference? No clue, not knowledgeable enough in C. I always thought double**[0] gives you a double* so you can then double*[0] and that should be equivalent to double**[0][0]. GCC doesn't seem to complain about this.

  7. 1 month ago
    Anonymous

    You're not that guy.

Comments are closed.