Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > structures, structures and more structures (questions about nestedstructures)

Reply
Thread Tools

structures, structures and more structures (questions about nestedstructures)

 
 
Alfonso Morra
Guest
Posts: n/a
 
      09-24-2005


Antonio Contreras wrote:

> Alfonso Morra wrote:
>
>>Hi,
>>
>>I have the ff data types :
>>
>>typedef enum {
>> VAL_LONG ,
>> VAL_DOUBLE ,
>> VAL_STRING ,
>> VAL_DATASET
>>}ValueTypeEnum ;
>>
>>typedef union {
>> long lval ;
>> double fval ;
>> char* sval ;
>> void* ptr ;
>>} Value ;
>>
>>typedef struct {
>> int magic ;
>> int version ;
>>}Header ;
>>
>>typedef struct {
>> char label[20] ;
>> id int ;
>>}Key ;
>>
>>typedef struct {
>> Header *hdr ;
>> char *subject ;
>> int subject_len ;
>> Key key ;
>> ValueTypeEnum type ;
>> Value value ;
>> int text_len ;
>> int size ;
>>}MotherStruct ;
>>
>>
>>If I have a variable declared as ff:
>>
>>MotherStruct *pMS = calloc(1,sizeof(MotherStruct*)) ;
>>

>
>
> <snip 3 questionz>
>
> Leaving aside your questions, which have already been adressed by other
> people, I think your call to calloc is ill written. Shouldn't it be:
>
> MotherStruct *pMS = calloc(1, sizeof(MotherStruct));
>
> ???
>
> You're allocating memory for a pointer to MotherStruct, not for a
> MotherStruct. If you dereference pMS you'll invoke undefined behaviour.
> Unless there's something I'm missing here.
>


Well spotted. That was a typo. I changed the line and posted it before
checking it. My Bad.

 
Reply With Quote
 
 
 
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      09-24-2005
Alfonso Morra wrote on 24/09/05 :
> Are you talking about ctors and dtors as in C++ ?


I don't have a clue... What is C++ ?


--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating more generic data structures Andrea Crotti C Programming 7 08-11-2010 12:47 PM
Kamaelia 0.4.0 RELEASED - Faster! More Tools! More Examples! More Docs! ;-) Michael Python 4 06-26-2006 08:00 AM
With a Ruby Yell: more, more more! Robert Klemme Ruby 5 09-29-2005 06:37 AM
DVD Verdict reviews: SYLVESTER AND THE MAGIC PEBBLE AND MORE MAGICAL TALES and more! DVD Verdict DVD Video 0 04-07-2005 08:10 AM
Type Casting IPv4 and IPv6 structures to Generic Structures tweak C Programming 14 06-11-2004 02:43 PM



Advertisments