![]() |
|
ALLEGRO_ANIMATED_BITMAP |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I dunno, I've started using Enums a lot more than I used to, and they are valid C, and you get better type checking, and you'll get warned if a switch doesn't cover all enum items (which is usually a good thing). Thomas Fjellstrom said: for( int i = 0;... // this is not allowed i believe either C99 and GCC is fine with that. C++ is as well (obviously). Quote: int i; for( i = 0;... // this is OK Depends. If you're using C89, it has to go at the top of the function, if you use C99, it can go in the for, or just before the for. -- |
count
Member #5,401
January 2005
|
Quote: for loop stuff Thanks! Will change that too. Don't know how many will use this with C89 but since it is easy to change I'll do it. Thomas Fjellstrom said: I dunno, I've started using Enums a lot more than I used to, and they are valid C and you get better type checking
I like them because of this reason too. That's why I wanted to use them... Alianix said: if (anim_instance->animation->type == ANIMATION::MULTIPLE_BITMAPS){} /* <-crime scene, this is C++*/
Is the problem that I access the enum via the ANIMATION struct? But if anyone is would point out what the problem with this is I would be glad
|
Arthur Kalliokoski
Second in Command
February 2005
![]() |
A struct in C uses a single dot, e.g. ANIMATION.MULTIPLE_BITMAPS They all watch too much MSNBC... they get ideas. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Arthur Kalliokoski said: A struct in C uses a single dot, e.g. ANIMATION.MULTIPLE_BITMAPS You can actually use enum items that way? I didn't think the enum was "namespaced" into the struct itself. But then I only started using Enums after I started using C++ more often. -- |
Alianix
Member #10,518
December 2008
![]() |
Yep that's news for me too, I don't see any good use of it in our situation yet though...Anyways if Chris wants to keep it that way that's totally fine. I actually kinda like it... ANIMATION.SET, pretty neat...;)
|
count
Member #5,401
January 2005
|
Hmm... when I change it to ANIMATION.MULTIPLE_BITMAPS i get a warning in msvc (C4832). // C4832.cpp // compile with: /W1 struct A { enum { e }; }; int main() { return A.e; // C4832 // try the following line instead // return A::e; } So MSVC wants it with :: With mingw I get an error: "...\animation_c.c|16|error: expected primary-expression before '.' token|"
|
Alianix
Member #10,518
December 2008
![]() |
It may be because of your file extension is .cpp so it assumes C++ code, but I'm pretty sure that :: is not C. It works like this for me: (gcc 4.3.2 linux) struct ANIMATION { enum { THISTYPE, THATTYPE }type; }ANIMATION; printf("%d\n", ANIMATION.type );
|
count
Member #5,401
January 2005
|
Hmm... I thought that there is a way to deal with enums and structs that is valid in C and C++. I want the code to be usable in a C as well in a C++ program. So I have to find a way that is correct in both languages.
|
weapon_S
Member #7,859
October 2006
![]() |
IIRC using an enum as a namespace (or struct) is not standard. |
|
|