× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Tue, Aug 25, 2020 at 5:34 PM Bruce Vining <bruce.vining@xxxxxxxxx> wrote:

The one language I really can't
stand, and it's just heritage I think, is C. If I add 1 to a pointer I am
anticipating addressing the next byte of storage, not the first byte of the
data type the pointer is associated with.

In case people are trying to follow along, I think a better way to
express that last part is:

In C, pointers and arrays are designed to be (basically) equivalent.
So if you increment a "pointer" by one, you are actually accessing the
next "element" of the array, which means you've advanced the pointer
by the *size of* the data type it's associated with.

And, whether or not that matches your intuition, of course it's just
the compiler trying to be helpful. After all, if you've declared a
pointer to 4-byte integers, it is vastly, vastly, vastly more likely
that you want to get the next 4-byte integer than that you want to get
the 2nd byte within a 4-byte integer. Further, if you've declared a
pointer to a 4-byte integer and you increment that memory address by
one byte, then if you try to de-reference the pointer at that point,
you'll be reading the 2nd, 3rd, and 4th byte of the first integer, and
the 1st byte of the next (and interpreting those 4 bytes you just read
as a 4-byte integer).

It's true that C has a comparatively fast and loose notion of types,
but it does have *some* notion of types! It's not all just bytes!

John Y.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.