home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19280 < prev    next >
Encoding:
Text File  |  1993-01-06  |  2.2 KB  |  68 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!microsoft!wingnut!russpj
  3. From: russpj@microsoft.com (Russ Paul-Jones)
  4. Subject: Re: Why would someone put 'char x[]' inside of a struct decl?
  5. Message-ID: <1993Jan05.223108.27490@microsoft.com>
  6. Date: 05 Jan 93 22:31:08 GMT
  7. Organization: Microsoft Corporation
  8. Summary: A correction
  9. References: <wyrr3hn@lynx.unm.edu> <C0CB20.201@netnews.jhuapl.edu>
  10. Followup-To: comp.os.ms-windows.programmer.misc
  11. Lines: 55
  12.  
  13. Followups directed to comp.os.ms-windows.programmer.misc.
  14.  
  15. In article <C0CB20.201@netnews.jhuapl.edu> bandy@netnews.jhuapl.edu (Mike Bandy) writes:
  16. >peter@deepthought.unm.edu (Peter Blemel) writes:
  17. >
  18. >>I'm trying (really I am) to write a Microsoft Windows app, and I've come across
  19. >>a structure (Prog ref, vol 4 pg90) that looks something like...
  20. >
  21. >>struct DialogBoxHeader {
  22. >>    char szMenuName[];
  23. >>    char szFaceName[];
  24. >>};
  25. >
  26. >>First, this reference sucks. It doesn't explain how to use this and a companion
  27. >>structure (on the following page) together. Second, I can't figure out how to
  28. >>initialize this structure(?). szMenuName isn't allocated any storage, and I can't
  29. >>allocate any for it because it's not a lvalue. 
  30. >
  31. >Look at the struct as:
  32. >
  33. >struct DialogBoxHeader {
  34. >    char *szMenuName;
  35. >    char *szFaceName;
  36. >};
  37. >
  38. >Then the fields are pointers to character strings that you supply.  So you
  39. >can do:
  40. >
  41. >#define MyMenuName "Projects"
  42. >...
  43. >struct DialogBoxHeader DBH;
  44. >...
  45. >DBH.sz_MenuName = MyMenuName;
  46. >
  47. >(Note, I'm not a Windows programmer, but AmigaDOS does similar things.)
  48.  
  49. I believe that the original poster was correct in reading the documentation 
  50. as describing a chunk of memory containing variable-length fields.  I 
  51. would say that the SDK documenation contains the illegal struct 
  52. definition not because the author made the mistake of replacing a 
  53. char * with an array of chars (which is not a reasonable thing to do), 
  54. but by way of a loose analogy.  I would agree with Peter that at the 
  55. very least the SDK should explain this kind of usage of illegal C.
  56.  
  57. There is no C construct that implements the Windows construct directly.
  58.  
  59. >-- 
  60. >
  61. >    Mike Bandy
  62. >    bandy@aplcomm.jhuapl.edu
  63. >    Johns Hopkins University / Applied Physics Lab
  64.  
  65. -Russ Paul-Jones
  66. russpj@microsoft.com
  67. Not speaking for Microsoft.
  68.