home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / c / 2634 < prev    next >
Encoding:
Text File  |  1992-09-15  |  1.7 KB  |  37 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!wupost!uwm.edu!ogicse!das-news.harvard.edu!spdcc!dirtydog.ima.isc.com!karl
  2. From: karl@ima.isc.com (Karl Heuer)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Scope of arguments in prototype
  5. Keywords: scope, prototypes
  6. Message-ID: <1992Sep15.224805.9790@ima.isc.com>
  7. Date: 15 Sep 92 22:48:05 GMT
  8. References: <1992Sep14.225546.4277@xilinx.com>
  9. Sender: usenet@ima.isc.com (news)
  10. Organization: Interactive Systems, Cambridge, MA 02138-5302
  11. Lines: 24
  12.  
  13. In article <1992Sep14.225546.4277@xilinx.com> lou@xilinx.com (Lou Sanchez-Chopitea) writes:
  14. >Hi,
  15. >    What is the scope of the arguments in a prototype? In particular do I have
  16. >to worry about "a" and "b" in:
  17. >    double func ( double a, int b);
  18. >if it is a header file, conflicting with variables a user might wish to define?
  19.  
  20. Identifiers declared as formal arguments in a prototype declaration have very
  21. short scope, so in that sense you're safe.  (This fact does cause problems if
  22. you try to declare something like
  23.     extern char *asctime(struct tm const *);
  24. since the short scope prevents this from serving as the first declaration of
  25. the struct tag; for this reason it's necessary to put the struct declaration
  26. before the prototype, or at least predeclare the tag with
  27.     struct tm;
  28. to establish a scope.)
  29.  
  30. However, there's a different danger: the header may exhibit incorrect behavior
  31. if the user, before including the header, has defined a *macro* with the name
  32. |a| or |b|.  For this reason, it's better to leave out the identifiers in
  33. declaration prototypes, or use names that are within your documented
  34. namespace.  ("__a" works if this is part of the standard library.)
  35.  
  36. Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
  37.