home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!microsoft!wingnut!russpj
- From: russpj@microsoft.com (Russ Paul-Jones)
- Subject: Re: Why would someone put 'char x[]' inside of a struct decl?
- Message-ID: <1993Jan05.223108.27490@microsoft.com>
- Date: 05 Jan 93 22:31:08 GMT
- Organization: Microsoft Corporation
- Summary: A correction
- References: <wyrr3hn@lynx.unm.edu> <C0CB20.201@netnews.jhuapl.edu>
- Followup-To: comp.os.ms-windows.programmer.misc
- Lines: 55
-
- Followups directed to comp.os.ms-windows.programmer.misc.
-
- 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;
- >
- >(Note, I'm not a Windows programmer, but AmigaDOS does similar things.)
-
- I believe that the original poster was correct in reading the documentation
- as describing a chunk of memory containing variable-length fields. I
- would say that the SDK documenation contains the illegal struct
- definition not because the author made the mistake of replacing a
- char * with an array of chars (which is not a reasonable thing to do),
- but by way of a loose analogy. I would agree with Peter that at the
- very least the SDK should explain this kind of usage of illegal C.
-
- There is no C construct that implements the Windows construct directly.
-
- >--
- >
- > Mike Bandy
- > bandy@aplcomm.jhuapl.edu
- > Johns Hopkins University / Applied Physics Lab
-
- -Russ Paul-Jones
- russpj@microsoft.com
- Not speaking for Microsoft.
-