home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13548 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  2.1 KB

  1. Path: sparky!uunet!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: zero-length datatype
  5. Message-ID: <TMB.92Sep11211332@arolla.idiap.ch>
  6. Date: 12 Sep 92 01:13:32 GMT
  7. References: <TMB.92Sep8141523@arolla.idiap.ch> <4947@holden.lulea.trab.se>
  8.     <HAYDENS.92Sep9215705@bullwinkle.juliet.ll.mit.edu>
  9.     <TMB.92Sep10120206@arolla.idiap.ch> <23650@alice.att.com>
  10. Sender: news@ai.mit.edu
  11. Reply-To: tmb@idiap.ch
  12. Distribution: comp
  13. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  14.     Perceptive)
  15. Lines: 34
  16. In-reply-to: ark@alice.att.com's message of 10 Sep 92 17:36:24 GMT
  17.  
  18. In article <23650@alice.att.com> ark@alice.att.com (Andrew Koenig) writes:
  19.  
  20.    There is one problem with `void' as a true datatype that I have not
  21.    been able to solve: ISO C says that
  22.  
  23.        void f(void);
  24.  
  25.    is a function with no arguments at all and C++ therefore follows suit.
  26.    Making void into a true type would therefore require some compatibility
  27.    warts; it is not clear exactly what would be necessary or what effect it
  28.    would have on the rest of the language.
  29.  
  30. I mentioned this in my posting; I don't think this is a serious
  31. problem, for the following reasons.
  32.  
  33. To remain compatible with C, you can interpret the above prototype as
  34. meaning either "a function taking no arguments" or as "a function
  35. taking exactly one argument of type 'void'". That is, it would be
  36. legal to call the above function as "f()" or "f(void())". Since there
  37. is no actual data being passed and no actual dereferencing happening,
  38. this is harmless.
  39.  
  40. Compiler writers might be encouraged to issue a warning when a
  41. declaration of "void f(void);" occurs in the C++ language context
  42. (rather than inside an 'extern "C"') _and_ the function is actually
  43. being used without arguments. Likewise, using any kind of "void" type
  44. cinside the C language context should be flagged as an error.
  45.  
  46. Maybe the interpretation of "void f(void)" as a function taking no
  47. arguments could eventually be phased out in the C++ language context.
  48. After all, K&R style declarations and definitions are also valid in
  49. ISO C but not in C++.
  50.  
  51.                     Thomas.
  52.