Steven D'Aprano wrote:
In C, it might be something similar to:

const int *a = &x;

Not quite, that makes whatever a points to constant, not a
itself. But you can do this:

    typedef int *ip;
    int x, y;
    const ip p = &x;

    void f(void) {
        *p = 42; /* ok */
        p = &y; /* not ok */
    }

Compiling this gives:

% gcc -c constptr.c
constptr.c: In function ‘f’:
constptr.c:7: error: assignment of read-only variable ‘p’

BTW, this shows that gcc thinks of const-declared things
as "read-only variables" rather than constants. Which is
a bit of a silly term when you think about it!

--
Greg
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to