Re: typeless data [structures]



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rob wrote:
> I seek to be able to store data in a static variable that has no
> specifically defined type/size.

AFAIK, C has no way to permit you to do that.

> 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.

I can think of a couple of ways to accomplish this goal, and none of them
involve untyped data.

> In my attempts of doing this (I don't know if it is even possible), I
> encountered a feature of some sort that seems to be legal, but yet I
> don't know what it does. It involves inserting a type followed by a
> colon followed by a constant. Here's an example:
>
> struct {
>
> int : 0;
> long : 5;
> short : 2;
> } s;
>
> What does this do?

It pads bitfields.

Say, you have two bitfields that you want to separate by eight bits. You'd
define a structure something like this...

struct {
int bit_field_1 : 4;
int : 8;
int bit_field_2 : 4;
} s;


> Does it have anything to do with the functionality I
> am after?

No, it doesn't

> When I attempted to cast this struct it wouldn't allow me to;
> it gave the error "cannot convert from '' to <type_name>".

Yah, I'd expect something like that

So, to solve your problem, try hiding your data in a char array, and cast its
address to a pointer to your structure.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFCm70gagVFX4UWr64RAtrXAKCxf/1VJaHuM5C91LoYKTXmn67L+wCeOFRo
jcjuCoGIaqdjodp5+IwqxWU=
=Ucqq
-----END PGP SIGNATURE-----
.



Relevant Pages

  • Re: Insurance and tax question
    ... Champ cast forth these pearls of wisdom ... > It has to be insured in its own right afaik. ...
    (uk.rec.motorcycles)
  • Re: John C. McGinley joins "Back" pilot
    ... AFAIK, he was the only member of the cast who has definitively said ... he'd be back for a ninth, Zach Braff- and Bill Lawrence-less season of ...
    (rec.arts.tv)
  • Re: Linq project and Datatable
    ... AFAIK it would work if you cast IEnumerableto IEnumerable but not the ... Blog: http://cs.rthand.com/blogs/blog_with_righthand/ ... Prev by Date: ...
    (microsoft.public.dotnet.framework)
  • Re: CAMELOT (1982) film of stage play
    ... Apologies - since I misread your info request; AFAIK, ... cast was not filmed, except in some excerpts shown on old Ed Sullivan ...
    (rec.arts.theatre.musicals)