home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!psinntp!cadkey!erics
- From: erics@cadkey.com (Eric Smith)
- Subject: Re: Why would someone put 'char x[]' inside of a struct decl?
- Message-ID: <1993Jan5.220614.4092@cadkey.com>
- Organization: cadkey
- References: <wyrr3hn@lynx.unm.edu> <C0CB20.201@netnews.jhuapl.edu>
- Date: Tue, 5 Jan 1993 22:06:14 GMT
- Lines: 41
-
- In article <C0CB20.201@netnews.jhuapl.edu> bandy@netnews.jhuapl.edu (Mike Bandy) writes:
- >peter@deepthought.unm.edu (Peter Blemel) writes:
- >
- >>I'm trying (really I am) to write a Microsoft Windows app, and I've come across
- >>a structure (Prog ref, vol 4 pg90) that looks something like...
- >
- >>struct DialogBoxHeader {
- >> char szMenuName[];
- >> char szFaceName[];
- >>};
- >
- >>First, this reference sucks. It doesn't explain how to use this and a companion
- >>structure (on the following page) together. Second, I can't figure out how to
- >>initialize this structure(?). szMenuName isn't allocated any storage, and I can't
- >>allocate any for it because it's not a lvalue.
- >
- >Look at the struct as:
- >
- >struct DialogBoxHeader {
- > char *szMenuName;
- > char *szFaceName;
- >};
- >
- >Then the fields are pointers to character strings that you supply. So you
- >can do:
- >
- >#define MyMenuName "Projects"
- >...
- >struct DialogBoxHeader DBH;
- >...
- >DBH.sz_MenuName = MyMenuName;
-
- No. The original poster was correct in his fear that this is not a
- structure at all, but just stuff laid out in memory. A C structure
- can't be used for the fields. I too have had a hard time figuring out
- DialogBoxIndirect, but with some effort, it can be made to work. The
- way to initialize the "structure" is with some calculations, a malloc,
- then some strcpy's and char* pointer arithmetic.
-
- Eric.
-
-