Re: Comparing pointers to NULL
- From: phil-news-nospam@xxxxxxxx
- Date: 11 Aug 2009 01:54:25 GMT
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/ |
-----------------------------------------------------------------------------
.
- Follow-Ups:
- Re: Comparing pointers to NULL
- From: Alexander Bartolich
- Re: Comparing pointers to NULL
- References:
- Comparing pointers to NULL
- From: Charlie Zender
- Re: Comparing pointers to NULL
- From: Kaz Kylheku
- Re: Comparing pointers to NULL
- From: Keith Thompson
- Re: Comparing pointers to NULL
- From: phil-news-nospam
- Re: Comparing pointers to NULL
- From: Kaz Kylheku
- Re: Comparing pointers to NULL
- From: Keith Thompson
- Re: Comparing pointers to NULL
- From: phil-news-nospam
- Re: Comparing pointers to NULL
- From: Keith Thompson
- Re: Comparing pointers to NULL
- From: phil-news-nospam
- Re: Comparing pointers to NULL
- From: Keith Thompson
- Comparing pointers to NULL
- Prev by Date: Re: Comparing pointers to NULL
- Next by Date: Re: detab utility challenge.
- Previous by thread: Re: Comparing pointers to NULL
- Next by thread: Re: Comparing pointers to NULL
- Index(es):
Relevant Pages
|