Re: Comparing pointers to NULL



On Mon, 10 Aug 2009 07:35:02 -0700 Keith Thompson <kst-u@xxxxxxx> wrote:
| phil-news-nospam@xxxxxxxx writes:
|> On Sun, 09 Aug 2009 01:34:27 -0700 Keith Thompson <kst-u@xxxxxxx> wrote:
|> | phil-news-nospam@xxxxxxxx writes:
| [...]
|> |> Will that education include that the following is valid (and what
|> |> it does)?
|> |>
|> |> 0[pointer]
|> |
|> | Yes, and yes, and in addition why it should never be used in serious
|> | code.
|>
|> I'm sure I'll disagree with it.
|
| Do you think that 0[pointer] *should* be used in serious code?

No. I think 0[pointer] *can* be used ... e.g. not prohibited.

I can read 0[pointer] in code just fine. I don't have to stop and think
about it at all. I might not even notice that form was in some code I
might read. Other aspects of other people's code I find harder to read
than this.

Had I designed the language from the beginning, I would have used the syntax
of [pointer] for all pointer dereference (e.g. leave out the 0). This does
not create any syntax ambiguity. I even used this syntax to index variable
name space in a BASIC language interpreter I wrote in college. If given a
string expression inside [] not used to index an array, it would index the
top of the variable namespace. I would have no qualms about using it for a
purpose like that in the future if I find myself designing a language, or
implementing one that I can extend (assuming it is compatible). The thing
of interest here is that the run time models of these other languages have
live string indexed namespaces for variables, while C has raw virtual memory
access. So if you think of 0 as being a reference to all of memory itself,
then 0[pointer] is just like using the pointer value to index memory.

BTW, the [pointer] syntax could be added as an extension to standard C now,
an causes no syntax conflicts I can see.

--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
.



Relevant Pages

  • Re: "Mastering C Pointers"....
    ... all means go ahead and dive right into the C language. ... Memory is a separate unit which just stores bits. ... A pointer at the hardware level _is an integer_. ... since loops make your logic more much ...
    (comp.lang.c)
  • Re: Garbage collection
    ... For example, it's perfectly legal to take a pointer object, break its ... memory that refers to the referenced block of memory, ... They manage their memory themselves *because* they care about it. ... other language feature you care to name: ...
    (comp.lang.c)
  • Re: Proposal for limited pointers
    ... to add a new type of pointers to the language that I have chosen to ... memory block allocated by malloc/calloc/realloc be immediately ...  Size of allocated memory is not enough. ... alongside the pointer so a limited pointer would be twice as big as ...
    (comp.std.c)
  • Re: Python syntax in Lisp and Scheme
    ... Lisp also has this to a certain degree: ... what language "paradigm" you are currently using. ... > conjecture is that additional syntax can make some things easier. ... I don't know a lot about the specifics of shared memory, ...
    (comp.lang.python)
  • Re: Python syntax in Lisp and Scheme
    ... Lisp also has this to a certain degree: ... what language "paradigm" you are currently using. ... > conjecture is that additional syntax can make some things easier. ... I don't know a lot about the specifics of shared memory, ...
    (comp.lang.lisp)