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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!psinntp!cadkey!erics
  3. From: erics@cadkey.com (Eric Smith)
  4. Subject: Re: Why would someone put 'char x[]' inside of a struct decl?
  5. Message-ID: <1993Jan5.220614.4092@cadkey.com>
  6. Organization: cadkey
  7. References: <wyrr3hn@lynx.unm.edu> <C0CB20.201@netnews.jhuapl.edu>
  8. Date: Tue, 5 Jan 1993 22:06:14 GMT
  9. Lines: 41
  10.  
  11. In article <C0CB20.201@netnews.jhuapl.edu> bandy@netnews.jhuapl.edu (Mike Bandy) writes:
  12. >peter@deepthought.unm.edu (Peter Blemel) writes:
  13. >
  14. >>I'm trying (really I am) to write a Microsoft Windows app, and I've come across
  15. >>a structure (Prog ref, vol 4 pg90) that looks something like...
  16. >
  17. >>struct DialogBoxHeader {
  18. >>    char szMenuName[];
  19. >>    char szFaceName[];
  20. >>};
  21. >
  22. >>First, this reference sucks. It doesn't explain how to use this and a companion
  23. >>structure (on the following page) together. Second, I can't figure out how to
  24. >>initialize this structure(?). szMenuName isn't allocated any storage, and I can't
  25. >>allocate any for it because it's not a lvalue. 
  26. >
  27. >Look at the struct as:
  28. >
  29. >struct DialogBoxHeader {
  30. >    char *szMenuName;
  31. >    char *szFaceName;
  32. >};
  33. >
  34. >Then the fields are pointers to character strings that you supply.  So you
  35. >can do:
  36. >
  37. >#define MyMenuName "Projects"
  38. >...
  39. >struct DialogBoxHeader DBH;
  40. >...
  41. >DBH.sz_MenuName = MyMenuName;
  42.  
  43. No.  The original poster was correct in his fear that this is not a
  44. structure at all, but just stuff laid out in memory.  A C structure
  45. can't be used for the fields.  I too have had a hard time figuring out
  46. DialogBoxIndirect, but with some effort, it can be made to work.  The
  47. way to initialize the "structure" is with some calculations, a malloc,
  48. then some strcpy's and char* pointer arithmetic.
  49.  
  50. Eric.
  51.  
  52.