Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rutgers!gatech!uflorida!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Fortran vs. C for numerical work Keywords: dependence analysis, C, Fortran Message-ID: <14562@smoke.brl.mil> Date: 23 Nov 90 17:50:42 GMT References: <21884@orstcs.CS.ORST.EDU> <1990Nov21.220816.15220@rice.edu> <17290@netcom.UUCP> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 27 In article <17290@netcom.UUCP> avery@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.