String help!

John Chambers jc at mit-athena.UUCP
Wed Mar 6 00:38:19 AEST 1985


Let's see, reasons for returning pointers to constant strings...?

Several times in the past couple years I have written routines that
end with code something like:
  ...
  fail:				/* Jump here for disasters*/
    errno = EGLORCH;
    fprintf(stderr,"***foo() FAILED.\n");
    return("???FOO???");
  }
This is for a function that normally returns a pointer to a string
of characters.  The idea is that if the caller doesn't notice the
failure and tries to use the return value, the program won't just
bomb inexplicably (as it might do if you return NULL); it will have
a character string that will tend to stand out wherever it pops up
later.  In this case, it doesn't much matter if the caller changes
the string, since it is basically a string of garbage anyway.

Anyone got any more examples?

			John Chambers



More information about the Comp.lang.c mailing list