C++ Logo

sg20

Advanced search

Re: Introducing references

From: rhkramer_at <rhkramer_at_[hidden]>
Date: Thu, 27 Jan 2022 10:22:42 -0500
Intentionally top posting.

As a failed wannabee C/C++ programmer ... <skip to below the aside>

<Aside on some of my background -- very ignorable, I think>

(I could, perhaps should give more background -- C was not taught when I went
to school (iirc, it was released the year I graduated -- I learned Algol,
Fortran, and then quite a variety of additional languages over time) but not
C/C++. I do have a project that I've wanted to do for some time (I won't say
how long exactly, but will say double digit years) that I'd prefer to program
in C/C++ -- a syntax highlighter for the Scintilla family of editors --
"native" syntax highlighters are written in C/C++but there are other options
(including writing in Lua (which I looked at a few times), and maybe /
probably almost any language using the programming interface that is
available).

Anyway, the way I attempted to learn C (and later C++) was not in a structured
classroom environment, more or less an ad hoc approach involving reading some
books (including, iirc, Kernigan and Ritchie (?) back "in the day".

</Aside on some of my background -- very ignorable, I think>

I always had a hard time with pointers (and the word "dereference", and then
when I started looking at C++ I found references, and never figured out why
(the advantage of) references over pointers (I figured it was just something to
confuse me even more ;-)

This thread is making that more clear to me, and I might try (either here, or
somewhere else) to summarize my (gradually dawning) new understanding -- maybe
a few bullet points to start (and maybe I won't always publish all of these):

   * a reference is more useful ("syntactic sugar"?) when passing parameters
to (or from) functions

   * a reference cannot be null, while a pointer can be

   * ...

I guess I'm just trying to say I'm glad I'm subscribed to this list and, at
least sometimes, finding helpful discussions like this.

Have a good day, and I hope to see more ;-)


On Wednesday, January 26, 2022 10:24:06 AM Victor Eijkhout via SG20 wrote:
> "Without a genuine use-case, references can make seem C++ look rather
> quirky! Instead, it is recommended that students be exposed to references
> in a practical fashion, such as when passing parameters to functions.”

Received on 2022-01-27 15:23:01