Sign in to follow this  
bluefox25

Transposing C into C++?

Recommended Posts

I am going through the Game Programming All In One book and I am using Dev C++ with Allegro and I was getting all these erors with linking this and that. I realized thaat part of the problem is that I set up the project as a C++ one instead of C, which is what all the source code is written in. I don't know C but would I be able to change the examples and write them with C++? If so how would I convert this one into C++. I ham getting this error with it is in C: 1:18 C:\Dev-Cpp\Projects\gETiNFO\<command line> missing '(' after predicate Here is the example: [/source] #include <stdlib.h> #include <allegro.h> int main(){ allegro_init(); printf("Allegro Version=%s\n",allegro_id); printf("\n Press Any Key To Exit"); allegro_exit(); system("PAUSE"); return 0; } END_OF_MAIN(); [/source] Thanks..........BlueFox

Share this post


Link to post
Share on other sites
That is all valid C++, except possibly for the END_OF_MAIN(), but i think that is a macro defined by allegro, so itll still be valid C++.

In general all C is valid C++, but ive been told there are a few exceptions. I rarely program in C++ or C , though so ive probably never noticed a language feature like that.

Share this post


Link to post
Share on other sites
There are certain bits of C which are not valid C++. A few of these bits cannot be transformed into legal C++ by rote, but require an understanding of the language and of exactly what a piece of code is doing.

All this, however, is academic. Dev-CPP will compile files with a .c extension as C, not C++. The error you're getting does not seem to be related to a C/C++ divide.

Share this post


Link to post
Share on other sites
Are you using a console project?

It's been a while since I've used Allegro but, IIRC, END_OF_MAIN() is a macro that allows you to compile a Win32 game and still write code as if you were in console/DOS mode (no need to declare and register a window class, use WinMain, initalize DirectX, etc...).

If you created a console project try it without the END_OF_MAIN() or, of course, create a windows project and then cut and paste.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this