strange behavior with **double

Discussion in 'C Programming' started by iesvs, Sep 27, 2007.

  1. iesvs

    iesvs Guest

    I got a double ** (double **coef).
    And gcc accept the syntax coef[j], it works.
    I don't understand why. For me coef[j] is not correct because it's
    a double ** and not type[][].
    If someone could explain me that.
    iesvs, Sep 27, 2007
    1. Advertisements

  2. iesvs

    Army1987 Guest

    I don't understand, where do you use that syntax? Please copy and
    paste the code. (It is well possible that it is correct.)
    Army1987, Sep 27, 2007
    1. Advertisements

  3. iesvs

    iesvs Guest

    I got this structure:

    struct matrix
    int c, r;
    double **coef;

    and this function to access it:

    double matrix_get (MATRIX *m, int i, int j)
    return m->coef[j];

    It works. But for me it's amazing.
    iesvs, Sep 27, 2007

  4. I think you really need to learn the basics of C. Array subscripting
    in C works by converting the array to a pointer (to its first element)
    and then adding the subscript and dereferencing. So subscripting is
    really a pointer operation, not an array operation.

    I could describe it in more detail, but that's what books are for.

    -- Richard
    Richard Tobin, Sep 27, 2007
  5. iesvs

    iesvs Guest

    I think you really need to learn the basics of C.

    HA HA HA. You made me laugh. Why did you say that ? Explain.
    I never use array because one day gcc ask me a cast because I was
    assuming that an int[] is an int *, but for it no, it's two different
    iesvs, Sep 27, 2007
  6. iesvs

    Hyuga Guest

    No offense, but I think you've proven Mr. Tobin's point.

    Hyuga, Sep 27, 2007
  7. iesvs

    iesvs Guest

    Explain please ? I like to learn things in C.
    iesvs, Sep 27, 2007
  8. checkout the FAQs at, esp. Chapter 6

    Bye, Jojo
    Joachim Schmitz, Sep 27, 2007
  9. iesvs

    CBFalconer Guest

    coef is a pointer to a pointer to double. coef[x] reads the gets
    the pointer coef, adds x to it (in units of sizeof *coef) returning
    a pointer to double. coef[x][y] does all that, adds y to the
    pointer to double, and returns the double to which that points.
    All this assumes that the various addresses are in range and
    contain what they are reputed to hold.
    CBFalconer, Sep 27, 2007
  10. iesvs

    iesvs Guest

    checkout the FAQs at, esp. Chapter 6

    Very very strange.

    #include <stdio.h>
    #include <stdlib.h>

    void aff (int *a)
    int i;
    for (i = 0; i < 6; i++)
    printf ("%d", a);

    int main (void)
    int a[6] = {1, 2, 3, 4, 5, 6};
    aff (a);
    return 0;

    //end of example

    They said that "a" is a direct value but I can use it like it was an
    indirect value. It's very strange. And nearly inconsistent. So it's
    like gcc transform aff (a) by aff (&a). It's ugly. The arithmetic of
    pointer is kicked with that. Not the classical arithmetic, the other
    arithmetic (void is 0, void * is 1, void ** is 2 etc., there gcc make
    -1 == 0, horrible for a mathematician, I know why I don't use array
    iesvs, Sep 27, 2007

  11. I can only repeat myself: read the FAQs. esp. Chapter 6...

    Bye, Jojo
    Joachim Schmitz, Sep 27, 2007
  12. iesvs

    iesvs Guest

    I can only repeat myself: read the FAQs. esp. Chapter 6...

    I rode the FAQ and understand it, but it's TERRIBLE, confuse a int *
    and int, what a terrible concept. I'm disappointed by the C. I thought
    it was mathematical consistent. But no.
    iesvs, Sep 27, 2007
  13. and in another thread...

    and in another thread...

    Perhaps it's time to ask the city watch to step up patrols near the
    Francine.Neary, Sep 27, 2007
  14. I didn't ask you to ride the FAQs bit to read them :cool:
    And no, an "int *" is not the same as an "int" and the FAQ doesn't claim
    that, I'm fairly certain. Read it again.

    Bye, Jojo
    Joachim Schmitz, Sep 27, 2007
  15. iesvs

    iesvs Guest

    I didn't ask you to ride the FAQs bit to read them :cool:
    Ok I past the FAQ :

    You see the image where it says that
    "a" is a "char"
    "p" is a "char *"
    , OK ? Look scrupulously the picture please.
    And after that you explain me why when I got a function like that :
    void f (char *)

    I could write f (p) like f(a) so it confuse char and char *.
    It's a proof.
    iesvs, Sep 27, 2007
  16. No it's a char []
    No it tells you that in this context a char[] is the same as a char *

    Bye, Jojo
    Joachim Schmitz, Sep 27, 2007
  17. iesvs

    iesvs Guest

    No it's a char []

    Ok, but it's a direct value, not an indirect value (p is an indirect
    value). And I can use it like an indirect value. For me it's the same
    thing than saying 0 = 1.

    In the past I thought that a char[] was exactly a char * (the same
    thing for the computer), so I find it correct to make f (a) where f
    is ... f (char *) and a a char[]. But now no I saw that it's not the
    same thing, and f (a) is incorrect for a mathematician (confuse a
    direct value and an indirect what a silly idea).
    iesvs, Sep 27, 2007
  18. iesvs

    Default User Guest

    1. Get a decent book on C.

    2. Read it.

    Default User, Sep 27, 2007
  19. C is a relatively simple, logical, and straightforward language. It is
    clear that it doesn't suit your way of thinking. I advise you not to
    use it, which would also save you making such a fool of yourself in
    J. J. Farrell, Sep 27, 2007
  20. iesvs

    Tor Rustad Guest

    J. J. Farrell wrote:


    "C is quirky, flawed and an enormous success"
    Dennis Ritchie

    OP might be young, and without prior knowledge of K&R2, C FAQ and "C
    Traps and Pitfalls", there are lots of bad habits outside c.l.c to pick
    up. :)
    Tor Rustad, Sep 27, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.