News for hackers. Stuff that matters.
Re:The 5-minute Guide to C Pointers by khakimov on Thursday August 16, 2012 @12:47AM (#4389952)
thanks, also recommend to read "What do people find difficult about C pointers?" http://stackoverflow.com/questions/4025768/what-do-people-fi...
Re:The 5-minute Guide to C Pointers by keporahg on Thursday August 16, 2012 @02:07AM (#4390122)
I never really had much of a problem with the syntax, but the point at which the behavior of pointers really clicked for me (after a night of many segfaults of course) was when I realized that when you pass a pointer to a function, you're sending a copy of that pointer, just like with any other primitive type. E.g:

    void foo(int *p)
    {
        /* assignment won't be persistent after foo() returns; need to send **p */
        p = (int *)malloc(1024 * sizeof(int));
    }
Not sure why my brain had decided to make an exception for pointers for the rule that all variables are passed as copies when I first learned C, but after that I never had any problems.
Re:The 5-minute Guide to C Pointers by RegEx on Thursday August 16, 2012 @02:32AM (#4390169)
I experienced the same frustration. The exercise that gave me the "ah-ha!" moment I needed was prepending to a linked list via the head instead of the tail: You need to pass the address of `head` into the function so that the new head is reflected in the calling environment when you say `head = np`.
Re:The 5-minute Guide to C Pointers by unwind on Thursday August 16, 2012 @04:41AM (#4390452)
... or have the list operation return the new list head, which can make it way cleaner. See glib's list APIs, for instance.
Re:The 5-minute Guide to C Pointers by RegEx on Thursday August 16, 2012 @12:00PM (#4391926)
Well I was simply meeting exercise requirements, which aren't necessarily the most practical.
Re:The 5-minute Guide to C Pointers by eswangren on Thursday August 16, 2012 @04:28PM (#4393490)
Just like any other type. Everything is passed by value in C. Everything.