Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,631 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Super-small var-type? [Re: Joey] #308300
02/02/10 18:59
02/02/10 18:59
Joined: May 2007
Posts: 2,043
Germany
Lukas Offline

Programmer
Lukas  Offline

Programmer

Joined: May 2007
Posts: 2,043
Germany
Isn't that exactly what I suggested with the flags? wink

Re: Super-small var-type? [Re: Lukas] #308308
02/02/10 19:12
02/02/10 19:12
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
in principle, but like that you can access the single bits directly. this feature is quite neat because noone knows about it ;-).

Re: Super-small var-type? [Re: Joey] #308312
02/02/10 19:18
02/02/10 19:18
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
@Joey: Wow, never heard about that. But this looks like just what I need, even without any #define s. One question remains, though...

Let's assume I have a struct and some boolean values within:

typedef struct {
unsigned int FLAG1 : 1;
unsigned int FLAG2 : 1;

...

}my_struct;


The var-type of th e flags is now "unsigned int". However, the ": 1;" statement tells the compiler to use just 1 Bit for that value, am I right so far? If so, does the ": 1;" statement kind of "override" the original space requirement of the var-type (here: unsigned int)?

Re: Super-small var-type? [Re: Alan] #308318
02/02/10 19:27
02/02/10 19:27
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
in principle, yes. in principle it does not matter what integer type you use here, as long as you don't use char FLAG : 15, which is obviously nonsense, and of course the type is important for the underlying arithmetic used (unsigned). also note that the code generated out of this might be inefficient (it depends on the compiler used).

you can always use sizeof(my_struct) to check the memory usage of your struct.

Re: Super-small var-type? [Re: Joey] #308326
02/02/10 20:08
02/02/10 20:08
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
I see. And about the efficiency-topic - since we're in the lite-C-forum here, I would like to use this with the standard-A7-commercial-compiler which comes with SED. Will it be able to handle it efficiently? Or should I rather use #define s? Does Lite-C itself even support bit-fields? (I suppose so, just to make sure)

On a web-page I read that "signed int flag1 :1;" will always have a value of either 0 or -1. However, the text didn't say anything about "unsigned int flag1 :1;"... May I run into problems here?

Last edited by Alan; 02/02/10 20:08.
Re: Super-small var-type? [Re: Alan] #308332
02/02/10 20:23
02/02/10 20:23
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
You have to use bit-fields as bit members are not supported by lite-C (AFAIK).

"Does Lite-C itself even support bit-fields?"
Yes. Probably you have already used them when setting and unsetting entity flags and so on.

Re: Super-small var-type? [Re: Saturnus] #308339
02/02/10 20:59
02/02/10 20:59
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
i don't know if the compiler supports it. atm flags are set via set() or reset() which implies the define-stuff with one or several big flag integers.

the 0 and -1 thing is due to the way negative numbers are stored in computers, it is always something like from -n,-n+1,...,0,...,n-1 - there's always one more negative number than positive numbers. i guess when you use unsigned it will be 0 and 1.

what are bit members (@saturnus), if i may ask?

Re: Super-small var-type? [Re: Joey] #308346
02/02/10 21:34
02/02/10 21:34
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
"what are bit members (@saturnus), if i may ask?"
I was referring to this syntax: "unsigned int flag: 1;" within a struct.
Just seemed appropriate to me. : )

However, this doesn't seem to compile in lite-C. And I think the unsigned modifier is ignored by lite-C, too.

Re: Super-small var-type? [Re: Saturnus] #308489
02/03/10 13:29
02/03/10 13:29
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
that's weird, i thought lite-c was fully ansi-c compliant, but i may be mistaken here.

Re: Super-small var-type? [Re: Joey] #308578
02/03/10 18:52
02/03/10 18:52
Joined: Oct 2007
Posts: 306
Austria
A
Alan Offline OP
Senior Member
Alan  Offline OP
Senior Member
A

Joined: Oct 2007
Posts: 306
Austria
Would be interesting to know if there is a list of features which original C supports but lite-C does not... Up to now I also thought that lite-C can do anything and everything ordinary C can do.

Page 2 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1