Fortran vs. C for numerical work
Doug Gwyn
gwyn at smoke.brl.mil
Sat Nov 24 04:50:42 AEST 1990
In article <17290 at netcom.UUCP> avery at netcom.UUCP (Avery Colter) writes:
>Well sure, from what I can tell, the primary structures of C, Pascal,
>and Fortran look pretty similar. After learning Fortran, C is coming
>along pretty naturally. The pointers and structures and unions are
>interesting new things, kinda like "Fortran with some bells and whistles".
While there aren't many legitimate applications for unions, most good
applications in C lean VERY heavily on structures and pointers. For
example, to add an item to a list in Fortran one normally hopes that
the array (or parallel set of arrays) holding list members was declared
with enough room, then stores the item at the next available location
in the array and increments the integer variable that is used to keep
track of the next available location. In C, however, the following is
much more likely:
...
node *AddItem( node *itemp, node **list ) {
node *np = (node *)malloc( sizeof(node) );
if ( np == NULL )
return NULL; /* out of heap space (unlikely) */
assert(itemp != NULL); /* else usage error */
*np = *itemp; /* copy the data */
assert(list != NULL); /* else usage error */
np->link = *list; /* attach current list, if any */
return *list = np; /* current node is new head */
}
You'll know you're reasonably proficient in C when code like the above
makes perfect sense to you.
More information about the Comp.lang.c
mailing list