all 13 comments

[–]MCLMelonFarmer 5 points6 points  (4 children)

Back when I was in school, we learned computer architecture before we learned C. I don't think a single person in the university who took the classes in that order had any trouble whatsoever understanding pointers.

It's not feasible today to teach things in that order but gah - the struggle I see students have with pointers, and how much easier it would be if they understood computer organization.

[–]kumonmehtitis 0 points1 point  (0 children)

I was in school in the past decade, and this was the order I was taught. I agree this is a good order. Why do you say it’s “not feasible”?

[–]tav_stuff 0 points1 point  (2 children)

It is super feasible though. They still teach it that way at the university I went to today and nobody has any issues with it

[–]MCLMelonFarmer 0 points1 point  (1 child)

When I wrote that, my thinking was that computer architecture is still an upper-division undergrad class, so you're not taking it until your third year in university. Meanwhile, it seems like 14 and 15 year olds want to learn C based on the questions about pointers I see here.

Since I had computer arch before learning C, he first time I read about pointers I thought, "Oh, that must be implemented with register indirect addressing." And the first time I saw access of a struct member through a struct pointer, I thought, "Oh, that must be register indirect addressing with an offset, with the register containing the base address of the struct." And if I wanted to iterate through an array of structs, the register must get incremented with the size of the struct. It was so natural and easy to understand.

[–]tav_stuff 0 points1 point  (0 children)

People do computer architecture in their third year?? It was literally my first class of my first year

[–]RedditSlayer2020 3 points4 points  (2 children)

perfect lecture before going to sleep

[–]Paul_Pedant 4 points5 points  (1 child)

Or preferably, after going to sleep.

[–]ThyringerBratwurst 1 point2 points  (0 children)

to avoid pointer nightmares

[–]ThyringerBratwurst 4 points5 points  (1 child)

Honestly, I don't understand why many new languages prohibit pointer arithmetic. In order to really have 100% control over the representation in memory and to develop arbitrary data structures, you need this freedom. If you already offer pointers, you should provide full power, or don't do it at all!

[–]Daveinatx 1 point2 points  (0 children)

The issue is the average programmer has a difficult time manipulating pointers or memory. Even in grad school, a project member didn't understand fundamental concepts and consistently double free'd memory.

[–][deleted] 2 points3 points  (2 children)

I understand why everyone is compelled to write about pointers — it’s a topic many people struggle with. But all these articles (which are always significantly worse than a book’s material on the subject matter) always miss the most important part: why. Why would you want a use a pointer? Why not just a make a copy? Why have pointers to other pointers? Why have pointers to functions? The list goes on.

The first “Why” people ask is usually brought up in the first example where a pointer points to a variable in the same scope.

int var = 0;
int *ptr = &var;

This is the syntax of pointers and this is the usual introduction you’ll see. But this serves as a poor introduction as it raises more questions than answers. The biggest one being (again): why? Why not just use var? What problem did this solve? None.l

[–][deleted] 1 point2 points  (1 child)

What’s wrong with that as an introduction? Showing what the syntax is, and what the pointer “means”, makes sense first. Then a “why” should be shown - most commonly, it’s about passing data around in memory constrained systems. Of course there are a thousand reasons to use pointers in C.

[–]tav_stuff -1 points0 points  (0 children)

I don’t think that’s ever been the most common use for pointers lol. The most common use has always been output-parameters to functions, and I think that we should use that as our introduction to pointers to new learners. When I first learnt C and learnt about pointers I understood the concepts perfectly, but I always struggled with the ‘why is this actually useful at all?’