Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: the first programming language: C

Reply
Thread Tools

Re: the first programming language: C

 
 
riccardo
Guest
Posts: n/a
 
      10-04-2010

> and for pointers?


The idea of pointers is not that tough to teach.. first start by
speaking of the memory and how it's addressed, than use some easy to get
examples of addressing.. you don't really need to get too deep in that,
just let them enjoy the pleasure of pointers.. otherwise teach them
Java.. less troubles, more recent language etc... the very essence of C
is pointers.. cutting them off almost makes C meaningless if compared to
more recent programming languages.
Those are jsut my 2cents
RM
 
Reply With Quote
 
 
 
 
August Karlstrom
Guest
Posts: n/a
 
      10-04-2010
On 2010-10-04 12:12, riccardo wrote:
[...]
> the very essence of C is pointers.. cutting them off almost makes
> C meaningless if compared to more recent programming languages.


In C, except from simulating call by reference, the only situations
where we really need pointers in high level application programming is
when working with

1. linked data structures (essential pointers)

2. dynamically allocated arrays (all references to elements can be index
based instead of pointer based)

3. function pointers.


/August

--
The competent programmer is fully aware of the limited size of his own
skull. He therefore approaches his task with full humility, and avoids
clever tricks like the plague. --Edsger Dijkstra
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      10-04-2010
August Karlstrom <(E-Mail Removed)> writes:
> On 2010-10-04 12:12, riccardo wrote:
> [...]
>> the very essence of C is pointers.. cutting them off almost makes
> > C meaningless if compared to more recent programming languages.

>
> In C, except from simulating call by reference, the only situations
> where we really need pointers in high level application programming is
> when working with
>
> 1. linked data structures (essential pointers)
>
> 2. dynamically allocated arrays (all references to elements can be index
> based instead of pointer based)
>
> 3. function pointers.


C array indexing is defined in terms of pointers.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-04-2010
Keith Thompson <(E-Mail Removed)> writes:
> August Karlstrom <(E-Mail Removed)> writes:
>> On 2010-10-04 12:12, riccardo wrote:
>> [...]
>>> the very essence of C is pointers.. cutting them off almost makes
>> > C meaningless if compared to more recent programming languages.

>>
>> In C, except from simulating call by reference, the only situations
>> where we really need pointers in high level application programming is
>> when working with
>>
>> 1. linked data structures (essential pointers)
>>
>> 2. dynamically allocated arrays (all references to elements can be index
>> based instead of pointer based)
>>
>> 3. function pointers.

>
> C array indexing is defined in terms of pointers.


For that matter, so are (all) function calls, though that can usually be
ignored in practice.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Dann Corbit
Guest
Posts: n/a
 
      10-04-2010
In article <i8dbi9$nfs$(E-Mail Removed)>, (E-Mail Removed)
says...
>
> On 2010-10-04 12:12, riccardo wrote:
> [...]
> > the very essence of C is pointers.. cutting them off almost makes
> > C meaningless if compared to more recent programming languages.

>
> In C, except from simulating call by reference, the only situations
> where we really need pointers in high level application programming is
> when working with
>
> 1. linked data structures (essential pointers)
>
> 2. dynamically allocated arrays (all references to elements can be index
> based instead of pointer based)
>
> 3. function pointers.


4. strings

5. I/O of any kind

6. Locales

7. Parsing

IOW, pretty much any place one would normally consider using C.

I guess that there are at least a dozen more cases where addresses ought
to be used in C.
 
Reply With Quote
 
BGB / cr88192
Guest
Posts: n/a
 
      10-04-2010

"Dann Corbit" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)-september.org...
> In article <i8dbi9$nfs$(E-Mail Removed)>, (E-Mail Removed)
> says...
>>
>> On 2010-10-04 12:12, riccardo wrote:
>> [...]
>> > the very essence of C is pointers.. cutting them off almost makes
>> > C meaningless if compared to more recent programming languages.

>>
>> In C, except from simulating call by reference, the only situations
>> where we really need pointers in high level application programming is
>> when working with
>>
>> 1. linked data structures (essential pointers)
>>
>> 2. dynamically allocated arrays (all references to elements can be index
>> based instead of pointer based)
>>
>> 3. function pointers.

>
> 4. strings
>
> 5. I/O of any kind
>
> 6. Locales
>
> 7. Parsing
>
> IOW, pretty much any place one would normally consider using C.
>
> I guess that there are at least a dozen more cases where addresses ought
> to be used in C.


one could distinguish between pointers and explicit pointer arithmetic...

pointers themselves are difficult to avoid (much like avoiding reference
types in Java), however, most uses of pointer arithmetic can be glossed over
and assumed not to exist if needed. granted, traditional C string handling
is effectively built around pointer arithmetic, meaning one would have to
essentially rethink how to approach string handling.

one possibility would be to essentially intern all the strings, and then
create a number of high-level string operations (each string itself is
assumed to be immutable).

in my case, I tend to use a hybrid strategy, typically using pointers (and
buffers) when more convinient, and interning and abstract strings in many
other cases.

IMO, going the other direction, and assuming strings to be passable mutable
arrays, is essentially the wrong direction.

or such...


 
Reply With Quote
 
August Karlstrom
Guest
Posts: n/a
 
      10-04-2010
On 2010-10-04 22:26, Keith Thompson wrote:
> C array indexing is defined in terms of pointers.


But you don't have to think of it as pointers (abstraction you see).


/August

--
The competent programmer is fully aware of the limited size of his own
skull. He therefore approaches his task with full humility, and avoids
clever tricks like the plague. --Edsger Dijkstra
 
Reply With Quote
 
August Karlstrom
Guest
Posts: n/a
 
      10-04-2010
On 2010-10-04 23:23, Dann Corbit wrote:
> In article<i8dbi9$nfs$(E-Mail Removed)>, (E-Mail Removed)
>> In C, except from simulating call by reference, the only situations
>> where we really need pointers in high level application programming is
>> when working with
>>
>> 1. linked data structures (essential pointers)
>>
>> 2. dynamically allocated arrays (all references to elements can be index
>> based instead of pointer based)
>>
>> 3. function pointers.

>
> 4. strings


Only if you want to use a library designed around pointers (e.g. the
standard library). Here is some string handling without pointer syntax:

#include <stdio.h>

int main(void)
{
char s[] = "Hello Dann";
int i;

i = 0;
while (s[i] != '\0') {
printf("%c\n", s[i]);
i++;
}

return 0;
}

> 5. I/O of any kind
>
> 6. Locales
>
> 7. Parsing


If the libraries are designed around pointers, then yes.

> IOW, pretty much any place one would normally consider using C.


Like for instance low-level system programming.


/August

--
The competent programmer is fully aware of the limited size of his own
skull. He therefore approaches his task with full humility, and avoids
clever tricks like the plague. --Edsger Dijkstra
 
Reply With Quote
 
ralph
Guest
Posts: n/a
 
      10-04-2010
On Mon, 4 Oct 2010 14:54:13 -0700, "BGB / cr88192"
<(E-Mail Removed)> wrote:

>
>"Dann Corbit" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)-september.org...
>> In article <i8dbi9$nfs$(E-Mail Removed)>, (E-Mail Removed)
>> says...
>>>
>>> On 2010-10-04 12:12, riccardo wrote:
>>> [...]
>>> > the very essence of C is pointers.. cutting them off almost makes
>>> > C meaningless if compared to more recent programming languages.
>>>

>>
>> I guess that there are at least a dozen more cases where addresses ought
>> to be used in C.

>
>one could distinguish between pointers and explicit pointer arithmetic...
>


I disagree as trying to make a distinction between "pointers" and
"pointer arithmetic", or between "pointers" and "addresses" in C IS
impossible.

Pointers are 'addresses'. Period. They are not 'references'. Period.

Two of the major stated goals for the C language is low-level access
to memory, and map language constructs to machine instructions. To
facilitate this, C provides the pointer data type. This data type
holds addresses and the declaration of one provides specific
instructions to the compiler to create equations for use when applying
arithmetic. (Not so dissimilar to how separate instructions are
applied to do arithmetic for longs, or for doubles.)

The only way to avoid what many seem to consider messy is a judicious
use of const, and/or another layer of indirection - See "Handles", or
use a language where References are supported.

-ralph
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-04-2010
ralph <(E-Mail Removed)> writes:
> On Mon, 4 Oct 2010 14:54:13 -0700, "BGB / cr88192"
> <(E-Mail Removed)> wrote:
>
>>
>>"Dann Corbit" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)-september.org...
>>> In article <i8dbi9$nfs$(E-Mail Removed)>, (E-Mail Removed)
>>> says...
>>>>
>>>> On 2010-10-04 12:12, riccardo wrote:
>>>> [...]
>>>> > the very essence of C is pointers.. cutting them off almost makes
>>>> > C meaningless if compared to more recent programming languages.
>>>>
>>>
>>> I guess that there are at least a dozen more cases where addresses ought
>>> to be used in C.

>>
>>one could distinguish between pointers and explicit pointer arithmetic...
>>

>
> I disagree as trying to make a distinction between "pointers" and
> "pointer arithmetic", or between "pointers" and "addresses" in C IS
> impossible.
>
> Pointers are 'addresses'. Period. They are not 'references'. Period.


The latter depends on what you mean by "references". For example, C++
has "references" (it also has pointers that are essentially identical to
C pointers), and C++ "references" are definitely very different from
pointers.

However, the C Standard's own definition of "pointer" uses the word
"reference". C99 6.2.5p20:

A _pointer type_ may be derived from a function type, an object
type, or an incomplete type, called the _referenced type_. A
pointer type describes an object whose value provides a reference
to an entity of the referenced type. A pointer type derived
from the referenced type T is sometimes called ‘‘pointer to
T’’. The construction of a pointer type from a referenced
type is called ‘‘pointer type derivation’’.

[...]

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
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
70-290 first or 70-291 first? MCSE 2 07-11-2006 03:30 AM
I'm lazy: how do I make the first databound record not display/chop off the first element from SqlDataSource ASP .Net 7 06-28-2006 10:24 AM
20D's first field trip. First Snake of Spring Celtic Boar Digital Photography 3 04-10-2005 09:40 PM
help with my first project on first job, how to read a strange file, thanks a lot!!!!!!! matt Java 9 10-27-2004 03:32 AM
FS: First Clamshell Laptop - First Laptop in Space - GRiD 1101 Compass Computer Dave Computer Information 0 09-22-2004 10:59 PM



Advertisments