Re: typeless data [structures]



"Rob" <iouswuoibev@xxxxxxxxxxx> wrote:
# I seek to be able to store data in a static variable that has no
# specifically defined type/size. Or to put it another way, I wish to
# create a structure of data but without the ability to reference its
# subcomponents until I cast it to another predefined type.

C wants to know the size of things when allocates space for variables. One
way around that is to use pointers, because the compiler knows the size of
pointers. You can use a (void*) pointer as your variable and then cast it
to a pointer of whatever struct you want.

# struct {
#
# int : 0;
# long : 5;
# short : 2;
# } s;
#
# What does this do? Does it have anything to do with the functionality I
# am after? When I attempted to cast this struct it wouldn't allow me to;
# it gave the error "cannot convert from '' to <type_name>".

It's about using integers smaller than their natural size packed into a
structure.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
You hate people.
But I love gatherings. Isn't it ironic.
.



Relevant Pages

  • Re: Array of pointers in a struct
    ... > This is an array of 27 pointers. ... cast it, there's a warning, if I don't, there isn't. ... > which is the first element of that array. ... > pointer to struct. ...
    (comp.lang.c)
  • Re: Simple question, err... I think
    ... Your nodes contain no other indication of which pointers are valid, ... struct CountedObject ... int is_red; ... bool lament(char const s) ...
    (comp.programming)
  • Re: porting problems encountered
    ... Tru64 compiles long variables to size 8 bytes while VMS and HP-UX ... platform, the size of the structure would be 12 bytes. ... when it got to the AS/400 with 128 bit pointers. ... Using the struct from before: ...
    (comp.os.vms)
  • Re: strict aliasing rules in ISO C, someone understands them ?
    ... I understand now that my interpretation of the standard was totally ... an aggregate is a struct or an array. ... struct s1 {int i; double d;}; ... Pointers are just a means of accessing the objects, ...
    (comp.lang.c)
  • Re: Array of pointers in a struct
    ... >typedef struct trieNode ... This is an array of 27 pointers. ... >And this is the code I make a new trie node, initialize and return it. ...
    (comp.lang.c)