Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Quad), 595 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
defining flags #421618
04/21/13 16:20
04/21/13 16:20
Joined: Nov 2008
Posts: 354
saeculum II
MPQ Offline OP
Senior Member
MPQ  Offline OP
Senior Member

Joined: Nov 2008
Posts: 354
saeculum II
Hi,

I want to use a variable which functions as a bit field. I read that I cannot use enum for that, but how do I define these in lite-c?

eg

enum status = { STAT_1 = 0x01, STAT_" = 0x04 , ...}

Thanks!


new project in early stage...

Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
Re: defining flags [Re: MPQ] #421620
04/21/13 17:18
04/21/13 17:18
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Code:
define CONST_1 1
define CONST_2 2
// etc.


Then you can combine the flags with the binary operators.


Always learn from history, to be sure you make the same mistakes again...
Re: defining flags [Re: Uhrwerk] #421626
04/21/13 18:31
04/21/13 18:31
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
For those who are not aware the 3rd flag would have to be 4, not 3. The 4th flag would be 8 and so on, i.e. 2^n.

Alternatively you can use the bit shift operator the same way as it is used in atypes.h:

Code:
#define FLAG1			(1<<0)	// flag1..flag8 for C-Script use
#define FLAG2			(1<<1)
#define FLAG3			(1<<2)
#define FLAG4			(1<<3)
#define FLAG5			(1<<4)
#define FLAG6			(1<<5)
#define FLAG7			(1<<6)
#define FLAG8			(1<<7)

#define INVISIBLE		(1<<8)
#define PASSABLE		(1<<9)
#define TRANSLUCENT	(1<<10)	// transparent
#define OVERLAY		(1<<12)
...



"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: defining flags [Re: MPQ] #421672
04/22/13 19:23
04/22/13 19:23
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Originally Posted By: MPQ
I want to use a variable which functions as a bit field
Make sure that the variable type holds all flags. An int holds 4 bytes (32bit) and a long holds 8 bytes (64bit). If you just have 8 flags, use a char, because that is stored as 1 byte. Especially in network scenarios such consideration are interesting.

Originally Posted By: MPQ
I read that I cannot use enum for that, but how do I define these in lite-c?

Enums are not supported in Lite-C and they aren't flags. They are just constant names assigned to a numeric integer value. So if you have in C/C++ e.g.
Code:
enum { Apple, Orange, Banana, Melon } Fruit;


you could do something like that:
Code:
Fruit fruit = Apple;



Internally, they translate to constants like 0, 1 and 2. So, to emulate enums in Lite-C, you could do this, although it involves more writing:
Code:
#define Apple 1
#define Orange 3
#define Banana 5
#define Melon 7

typedef int Fruit;

Fruit fruit = Apple;

if (fruit == Melon)
   error("Shh you got to, shake it, shh shake it, shake it, got to shake it");
else
   if (fruit == Banana)
      error("(Shake it sugar) shake it like a Polaroid Picture");



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

Gamestudio download | chip programmers | 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