C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

please give me more examples about c_faq 2.6 ?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language (Moderated)
View previous topic :: View next topic  
Author Message
guoliang
Guest





PostPosted: Sat Apr 28, 2007 1:58 am    Post subject: please give me more examples about c_faq 2.6 ? Reply with 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: 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





PostPosted: Tue May 01, 2007 9:11 am    Post subject: Re: please give me more examples about c_faq 2.6 ? Reply with quote



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





PostPosted: Tue May 01, 2007 9:11 am    Post subject: Re: please give me more examples about c_faq 2.6 ? Reply with quote



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





PostPosted: Mon May 07, 2007 9:12 am    Post subject: Re: please give me more examples about c_faq 2.6 ? Reply with quote

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






PostPosted: Mon May 07, 2007 9:12 am    Post subject: Re: please give me more examples about c_faq 2.6 ? Reply with quote

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





PostPosted: Wed May 09, 2007 10:37 pm    Post subject: Re: please give me more examples about c_faq 2.6 ? Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.