Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > References and pointers

Reply
Thread Tools

References and pointers

 
 
CBFalconer
Guest
Posts: n/a
 
      01-01-2008
cr88192 wrote:
> "CBFalconer" <(E-Mail Removed)> wrote in message
>> cr88192 wrote:
>>> Simon Saize <(E-Mail Removed)> wrote:
>>>
>>>> What's the point of having references (&)? Why don't we just
>>>> use pointers (*)?
>>>
>>> The sense of using references in ?++ instead of pointers is to
>>> avoid annoying checking pointers for NULL

>>
>> There are NO references in the C language. None.
>>
>> Follow-ups set to remove the idiotic C and C++ cross-post.

>
> please try to make it more clear who you are responding to...
> this comes off seeming like I had written the text you are
> responding to, but I did not.


You wrote the line beginning "The sense of ...", and it was (and
is) so marked. I don't see your problem.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee, Frohe Weihnachten
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      01-01-2008
[Cross-post to comp.lang.c++ dropped]
jacob navia <(E-Mail Removed)> writes:
> James Kanze wrote:
>> On Jan 1, 2:06 pm, jacob navia <(E-Mail Removed)> wrote:
>>> James Kanze wrote:
>>>> On Dec 31 2007, 8:07 pm, Simon Saize <(E-Mail Removed)> wrote:
>>>>> I believe they exist in some versions of C, e.g. lcc-win which
>>>>> also supports Operator Overloading.

>>
>>>> If the language supports operator overloading and references,
>>>> it's not C. If a compiler supports them, then it is not a C
>>>> compiler. (And presumably, discussion of it isn't relevant in
>>>> comp.lang.c.)

>>
>>> As you may know, the C standards does NOT forbid any extensions.
>>> The extensions in lcc-win are done according to the specifications
>>> for extensions: no new keywords.

>>
>> If they result in syntax that wouldn't be legal C, a C compiler
>> is required to output a diagnostic. And regardless, they aren't
>> C, and certainly aren't relevant to comp.lang.c (and even less
>> comp.lang.c++).

>
> OK. That's your opinion.
>
> I disagree.


Ok, let's follow this line of reasoning.

A C compiler could provide extensions to do nearly anything, as long
as the extensions don't affect the behavior of any strictly conforming
program, and as long as a diagnostic is still issued for any violation
of a syntax rule or contstraint. Such a compiler could implement all
of Fortran, or all of Lisp, or all of Intercal or Befunge, or HTML, or
English, as long as it issues the required diagnostic. (There are
some highly obfuscated programs that are legal Fortran and legal C
with different meanings; let's say those are treated as C in
conforming mode.)

I presume you recognize that there's a point at which such extensions
become off-topic. Where, in your opinion, is that point? It's my
opinion that lcc-win's extensions are beyond the scope of this
newsgroup, partly because comp.compilers.lcc already exists; you
obviously disagree. What *would* be off-topic, and why do you draw
the line where you do?

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      01-01-2008
Simon Saize <(E-Mail Removed)> wrote in comp.lang.c:

> Hi -
>
> What's the point of having references (&)? Why don't we just use
> pointers (*)?
>
> Thanks.


I don't know if anyone's interested, but I have a little trick for
implementing references in C:

The function "CopyUntilNull" copies TChar's from psrc to pdest, but it
also updates the calling function's pointer. You'd use it like so:

TChar buf[NUM],
*p = buf;

CopyUntilNull(&p,some_array_1);
CopyUntilNull(&p,some_array_2); /* p has incremented value */
CopyUntilNull(&p,some_array_3); /* p has incremented value */

Here's the function that simulates taking a reference to a pointer:

void CopyUntilNull(TChar **const ppdest, TChar const *psrc)
{
# define pdest (*ppdest)

/* Now pdest is an L-value, just as if the
function parameter had been TChar *&pdest */

while (*++pdest = *++psrc);

# undef pdest
}

This isn't a magnificient example of my "trick" (i.e. it'd be more
efficient to use a local pointer and then set *ppdest at the very end so
as to have one level of indirection instead of two), but you get the
idea.

--
Tomás Ó hÉilidhe
 
Reply With Quote
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      01-01-2008
"Tomás Ó hÉilidhe" <(E-Mail Removed)> wrote in comp.lang.c:


> while (*++pdest = *++psrc);


That sort of is and isn't a typo. I had to alter the code slightly before
posting (to remove crap people didn't need to see). But of course it would
make more sense as:

while (*pdest++ = *psrc++);

--
Tomás Ó hÉilidhe
 
Reply With Quote
 
cr88192
Guest
Posts: n/a
 
      01-02-2008

"CBFalconer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> cr88192 wrote:
>> "CBFalconer" <(E-Mail Removed)> wrote in message
>>> cr88192 wrote:
>>>> Simon Saize <(E-Mail Removed)> wrote:
>>>>
>>>>> What's the point of having references (&)? Why don't we just
>>>>> use pointers (*)?
>>>>
>>>> The sense of using references in ?++ instead of pointers is to
>>>> avoid annoying checking pointers for NULL
>>>
>>> There are NO references in the C language. None.
>>>
>>> Follow-ups set to remove the idiotic C and C++ cross-post.

>>
>> please try to make it more clear who you are responding to...
>> this comes off seeming like I had written the text you are
>> responding to, but I did not.

>
> You wrote the line beginning "The sense of ...", and it was (and
> is) so marked. I don't see your problem.
>


no, I did not.

note the:
<
and
>


around that chunk of text.
OE was failing to properly quote, so I added said quotes manually.

now, you attribute to me the text I was responding to.
that is what I was objecting to.


another clue should have been this:
in most casual text, I don't capitalize.
in the case of that text, the poster does capitalize, and uses a different
set of gramatic patterns.


> --
> Merry Christmas, Happy Hanukah, Happy New Year
> Joyeux Noel, Bonne Annee, Frohe Weihnachten
> Chuck F (cbfalconer at maineline dot net)
> <http://cbfalconer.home.att.net>
>
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>



 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-02-2008
CBFalconer <(E-Mail Removed)> writes:
> cr88192 wrote:
>> "CBFalconer" <(E-Mail Removed)> wrote in message
>>> cr88192 wrote:
>>>> Simon Saize <(E-Mail Removed)> wrote:
>>>>
>>>>> What's the point of having references (&)? Why don't we just
>>>>> use pointers (*)?
>>>>
>>>> The sense of using references in ?++ instead of pointers is to
>>>> avoid annoying checking pointers for NULL
>>>
>>> There are NO references in the C language. None.
>>>
>>> Follow-ups set to remove the idiotic C and C++ cross-post.

>>
>> please try to make it more clear who you are responding to...
>> this comes off seeming like I had written the text you are
>> responding to, but I did not.

>
> You wrote the line beginning "The sense of ...", and it was (and
> is) so marked. I don't see your problem.


No, cr88192 didn't *originally* write that line; Alexey Stepanyan did.
But cr88192 quoted Alexey's text by preceding it with a line
containing just "<", and following it with a line containing just ">",
rather than the traditional "> " prefix on each line.

cr88192: if you want correct attributions, use the conventional
quoting conventions.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
cr88192
Guest
Posts: n/a
 
      01-02-2008

"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> CBFalconer <(E-Mail Removed)> writes:
>> cr88192 wrote:
>>> "CBFalconer" <(E-Mail Removed)> wrote in message
>>>> cr88192 wrote:
>>>>> Simon Saize <(E-Mail Removed)> wrote:
>>>>>
>>>>>> What's the point of having references (&)? Why don't we just
>>>>>> use pointers (*)?
>>>>>
>>>>> The sense of using references in ?++ instead of pointers is to
>>>>> avoid annoying checking pointers for NULL
>>>>
>>>> There are NO references in the C language. None.
>>>>
>>>> Follow-ups set to remove the idiotic C and C++ cross-post.
>>>
>>> please try to make it more clear who you are responding to...
>>> this comes off seeming like I had written the text you are
>>> responding to, but I did not.

>>
>> You wrote the line beginning "The sense of ...", and it was (and
>> is) so marked. I don't see your problem.

>
> No, cr88192 didn't *originally* write that line; Alexey Stepanyan did.
> But cr88192 quoted Alexey's text by preceding it with a line
> containing just "<", and following it with a line containing just ">",
> rather than the traditional "> " prefix on each line.
>
> cr88192: if you want correct attributions, use the conventional
> quoting conventions.
>


OE does this annoying thing, far too often, of leaving out all the '> 's. I
have not been able to figure out why, or how to fix it, so often, I am lazy
and just use the '< ... >' convention.

otherwise, I have to go and manually add '> ' to damn near every line, and
this is most often not worthwhile.


> --
> Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
> [...]
> "We must do something. This is something. Therefore, we must do this."
> -- Antony Jay and Jonathan Lynn, "Yes Minister"



 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-02-2008
CBFalconer said:

<snip>

> The point is that the only usage difference is in the calling
> module.


Er, so?

> The actual receiving code is exactly the same (although it
> may not be written identically).


It doesn't look the same to me. In one case, you have T *bar, and in the
other, you have T& bar.

> So now we need two different
> prototypes for the same function.


This is not obvious to me. They take different parameter types, so they
can't be the same function.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      01-02-2008
On Jan 1, 7:09 pm, jacob navia <(E-Mail Removed)> wrote:
> James Kanze wrote:
> > On Jan 1, 2:06 pm, jacob navia <(E-Mail Removed)> wrote:
> >> James Kanze wrote:
> >>> On Dec 31 2007, 8:07 pm, Simon Saize <(E-Mail Removed)> wrote:
> >>>> I believe they exist in some versions of C, e.g. lcc-win which
> >>>> also supports Operator Overloading.


> >>> If the language supports operator overloading and references,
> >>> it's not C. If a compiler supports them, then it is not a C
> >>> compiler. (And presumably, discussion of it isn't relevant in
> >>> comp.lang.c.)


> >> As you may know, the C standards does NOT forbid any extensions.
> >> The extensions in lcc-win are done according to the specifications
> >> for extensions: no new keywords.


> > If they result in syntax that wouldn't be legal C, a C compiler
> > is required to output a diagnostic. And regardless, they aren't
> > C, and certainly aren't relevant to comp.lang.c (and even less
> > comp.lang.c++).


> OK. That's your opinion.


> I disagree.


The charter of the group is not my opinion. Neither is the
contents of the C standard. One thing the charter insists on is
that the subject be relevant to all (or at least most)
mainstream C implementations.

As for opinion, yes: add references, operator overloading, and
who kows what all else to C, and you no longer have C, but
rather a crippled and broken C++.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-02-2008
James Kanze said:
> On Jan 1, 7:09 pm, jacob navia <(E-Mail Removed)> wrote:
>> James Kanze wrote:
>> > On Jan 1, 2:06 pm, jacob navia <(E-Mail Removed)> wrote:
>> >> James Kanze wrote:


<snip>

>> >>> If the language supports operator overloading and references,
>> >>> it's not C. If a compiler supports them, then it is not a C
>> >>> compiler. (And presumably, discussion of it isn't relevant in
>> >>> comp.lang.c.)
>> >> As you may know, the C standards does NOT forbid any extensions.
>> >> The extensions in lcc-win are done according to the specifications
>> >> for extensions: no new keywords.
>> > If they result in syntax that wouldn't be legal C, a C compiler
>> > is required to output a diagnostic. And regardless, they aren't
>> > C, and certainly aren't relevant to comp.lang.c (and even less
>> > comp.lang.c++).

>
>> OK. That's your opinion.

>
>> I disagree.

>
> The charter of the group is not my opinion. Neither is the
> contents of the C standard. One thing the charter insists on is
> that the subject be relevant to all (or at least most)
> mainstream C implementations.


The comp.lang.c group has no charter. I'm not sure about comp.lang.c++ - to
which this thread is crossposted - but I would guess that it doesn't have
a charter either; and even if it does, it's very unlikely that it
constrains the group to subjects relevant only to C implementations!

I agree with you, however, that extensions are not considered topical in
comp.lang.c (nor, as far as I'm aware, in comp.lang.c++).

Nevertheless, I think you're wrong to suggest that an implementation that
provides extensions cannot be a C implementation. The ISO C Standard
explicitly permits extensions.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
Typedef A references struct B which references struct A which... DanielEKFA C++ 8 05-16-2005 10:26 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
how to understand references to variables and references to constants are distinguished? baumann.Pan@gmail.com C++ 3 11-10-2004 04:16 AM
Pointers and References (and References to Pointers) Roger Leigh C++ 8 11-17-2003 10:14 AM



Advertisments