 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
guoliang Guest
|
Posted: Sat Apr 28, 2007 1:58 am Post subject: please give me more examples about c_faq 2.6 ? |
|
|
hi:
why some code use this define:
struct name {
int namelen;
char namestr[1];
};
and how to use it?
how to substitute it by standard method ?
thanks!
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Barry Schwarz Guest
|
Posted: Tue May 01, 2007 9:11 am Post subject: Re: please give me more examples about c_faq 2.6 ? |
|
|
On 27 Apr 2007 20:58:22 GMT, "guoliang" <poster.gil (AT) gmail (DOT) com> wrote:
| Quote: | hi:
why some code use this define:
struct name {
int namelen;
char namestr[1];
};
and how to use it?
how to substitute it by standard method ?
Google the phrase "struct hack" |
Remove del for email
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
jg Guest
|
Posted: Tue May 01, 2007 9:11 am Post subject: Re: please give me more examples about c_faq 2.6 ? |
|
|
On Apr 27, 1:58 pm, "guoliang" <poster....@gmail.com> wrote:
| Quote: | hi:
why some code use this define:
struct name {
int namelen;
char namestr[1];
};
and how to use it?
how to substitute it by standard method ?
|
You can have a variable-size struct. For example,
struct names *p1 = malloc(sizeof(name1) + sizeof(name1) -1); // ignore
alignments....
This way, you can have a compack representation of names..
JG
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Joel C. Salomon Guest
|
Posted: Mon May 07, 2007 9:12 am Post subject: Re: please give me more examples about c_faq 2.6 ? |
|
|
| Quote: | struct name {
int namelen;
char namestr[1];
};
You can have a variable-size struct. For example,
struct names *p1 = malloc(sizeof(name1) + sizeof(name1) -1); // ignore
alignments....
|
I had to work with a software library once (EVA) where /every/ structure
was only partly defined because there were variable-length arrays of
structures of variable length including /multiple/ variable-length
arrays of…
They didn't even have the courtesy of including the macros that might
have made unpacking these structures reasonable.
--Joel
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Guest
|
Posted: Mon May 07, 2007 9:12 am Post subject: Re: please give me more examples about c_faq 2.6 ? |
|
|
On Apr 28, 1:58 am, "guoliang" <poster....@gmail.com> wrote:
| Quote: | hi:
why some code use this define:
struct name {
int namelen;
char namestr[1];
};
and how to use it?
how to substitute it by standard method ?
thanks!
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sor
if u are using struct then u are combining too many data type into |
single which is defined......u have given name this user defined
struct with name ..
u can access it as in main
we define it as name n1;
scanf("%d",n1.namelen)
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
WillerZ Guest
|
Posted: Wed May 09, 2007 10:37 pm Post subject: Re: please give me more examples about c_faq 2.6 ? |
|
|
er.apoorva (AT) gmail (DOT) com wrote:
| Quote: | On Apr 28, 1:58 am, "guoliang" <poster....@gmail.com> wrote:
hi:
why some code use this define:
struct name {
int namelen;
char namestr[1];
};
and how to use it?
how to substitute it by standard method ?
thanks!
--
comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sor
if u are using struct then u are combining too many data type into
single which is defined......u have given name this user defined
struct with name ..
u can access it as in main
we define it as name n1;
scanf("%d",n1.namelen)
|
In addition to being nigh-on incomprehensible, your response is also wrong.
struct name { /*...*/ };
Does not, in C, define a type called "name". It does in C++, but this
isn't a C++ newsgroup is it?
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|