Allegro.cc - Online Community

Allegro.cc Forums » The Depot » ALLEGRO_ANIMATED_BITMAP

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
ALLEGRO_ANIMATED_BITMAP
Thomas Fjellstrom
Member #476
June 2000
avatar

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

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.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

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.

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...
But since I'm more used to C++ than to C I don't know I don't know what is wrong with this statement in C

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?
Already googled it, but found nothing usefull yet... will search more later.

But if anyone is would point out what the problem with this is I would be glad :)

Arthur Kalliokoski
Second in Command
February 2005
avatar

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
avatar

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.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Alianix
Member #10,518
December 2008
avatar

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).
MSDN said the following:

// 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
avatar

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.
Seems the defines are the easiest solution for now unless someone can point me in the right direction regarding this enum topic...

weapon_S
Member #7,859
October 2006
avatar

 1   2   3   4 


Go to: