Re: typeless data [structures]
- From: Lew Pitcher <lpitcher@xxxxxxxxxxxx>
- Date: Mon, 30 May 2005 21:25:52 -0400
-----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-----
.
- References:
- typeless data [structures]
- From: Rob
- typeless data [structures]
- Prev by Date: Re: sscanf and int64 in Win32 and Unix - different results?
- Next by Date: Re: sscanf and int64 in Win32 and Unix - different results?
- Previous by thread: typeless data [structures]
- Next by thread: Re: typeless data [structures]
- Index(es):
Relevant Pages
|