just wondering... (something about c++ i noticed)

Discussion about everything. New games, 3d math, development tips...
Post Reply
noals
Posts: 70
Joined: Sun May 18, 2008 2:59 pm

just wondering... (something about c++ i noticed)

Post by noals »

hi,

why the hell does everyone have to make their own object for int, float, string and stuffs like that ?
i mean c++ is an OO programing language so people make an "object" and you use it with c++ that include basic fonction as int, string and the kind, right ?
so whats the problem with people making their own stuff, isnt the c++ int or float good enough for them ?

just wondering...
Strong99
Admin
Posts: 687
Joined: Fri Mar 31, 2006 7:06 pm
Location: Netherlands
Contact:

Re: just wondering... (something about c++ i noticed)

Post by Strong99 »

I'm not sure what you mean, but in Irrlicht we don't have separate float or int objects, s32 (int) and f32 (float) are type definitions for example. This is done to ensure the types are the same on other platforms. So one could change the type without having to change it through the code, just replace the type and the typedef keeps working.

The typedefinitions can be found here:
http://irrlicht.sourceforge.net/docu/ir ... ource.html
As you can see, they differ for MSC and other compilers.

For strings we do use a separate object. This is due to the fact a string is a collection of characters and the string implementation differs on several platforms.
CuteAlien
Admin
Posts: 9745
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: just wondering... (something about c++ i noticed)

Post by CuteAlien »

Depends...

First string and int are very different. int is a basic type while string is a class which is only available through libraries.

The original types like int, float etc. are all platform dependent, so you can't say how large an integer can be without knowing the platform (it's larger on a 64-bit platform than on a 32-bit platform for example, also wchar_t can be 2 bytes or 4 bytes). To work around this people started creating their own basic types like you see in Irrlicht with irr::s32 to be able to have an indentical sized value on all platforms. But certainly so many people started doing that, that at some time the compiler vendors decided to add something for that - and as usual they couldn't decide at first so we got int32_t and __int32. So there are people working around that and offering headers which ensure one of them (usually int32_t) is available on all platforms, but this again takes the risk that it conflicts with other libraries which had the same idea. So really just using an own type in your library is probably still the safest way when you try to support several vendors and platforms and compiler versions. And certainly all that stuff didn't exist that back when Irrlicht was written.

Strings are another topic. Back in the days Irrlicht was written the standard library still had some troubles on some compilers. So lots of people thought it would be a good idea writing own libraries which generally had way more problems, but oh well - that's life. There had also been some advantages as you could make custom libraries faster than STL which was nice in game programming, although I don't see this in Irrlicht (I tested, STL is nearly throughout faster). The only reason I can think of these days to keep own string classes around are backward compatibility (changing it would break every code out there using Irrlicht, so nothing you do unless you have no alternatives) and maybe platforms where STL does not yet exist (I'm not sure if there are such platforms these days). Starting from scratch now it would be pretty crazy not using STL strings and personally I rather wish we could just switch to STL and kick out our own core-classes as I prefer STL by a far, far(!) margin.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
noals
Posts: 70
Joined: Sun May 18, 2008 2:59 pm

Re: just wondering... (something about c++ i noticed)

Post by noals »

i was wondering about that because i try to use newton so i will need to convert some stuff but thats another topic, i should be posting in the beginner help later about it..
as a result it just remininded me how the world is divided and confusing.

thx for your answers.
Post Reply