home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!zeppo.uccs.edu!sanluis!dbbergac
- From: dbbergac@sanluis (Dave Bergacker)
- Newsgroups: comp.std.c
- Subject: Return values from recursive function
- Date: 23 Nov 1992 23:52:36 GMT
- Organization: University of Colorado at Colorado Springs
- Lines: 31
- Message-ID: <1erqs4INN7aa@zeppo.uccs.edu>
- NNTP-Posting-Host: sanluis.uccs.edu
- X-Newsreader: TIN [version 1.1 PL6]
-
-
- Hi, I teach a 'C' class, and in a recent assignment, a student turned in
- code that looks like:
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- int main(void)
- {
- char *s1 = "mom", *s2 = "dad";
- int streq(const char *s1, const char *s2);
-
- printf("Comparing strings %s and %s\n",s1,s2);
- printf("The result was %d\n",streq(s1,s2));
- printf("The C strcmp function returns %d\n",strcmp(s1,s2));
- }
-
- int streq(const char *s1, const char *s2)
- {
- if ( !*s1 || ( *s1 != *s2 )) return *s1 - *s2;
- else streq(++s1,++s2);
- }
-
- Notice that there was no explicit return from the else branch, yet this
- code worked on Borlands TC (version unknown) and gcc version 2.2.2. Does
- ANSI specify anything about this behavior? Regretably I do NOT have a
- copy of the standard.
- --
- Happy Holidays,
- Dave Bergacker
- The opinions expressed are not those of UCCS, nor should they be.
-