portability and wxInt32

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
cecilio
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Fri Dec 03, 2004 8:44 am
Location: spain
Contact:

portability and wxInt32

Post by cecilio » Mon Feb 07, 2005 10:59 am

I am starting to use wxWidgets so perhaps my question is stupid: what is the utility of using wxInt32 and the others in declarations if all wxWidgets code use int and long instead?

After having to use explicit cast on some cases I am starting questioning the utility of wxINt32 declarations and thinking about the convenience of changing all my wxInt32 declarations to long.

Any comments please? Thank you.

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Tue Feb 08, 2005 7:51 am

Hi!
Using these classes and the wxSWAP_XXX macros can get you out of trouble when saving data on a big endian platform (like the Mac) and read it on a little endian platform (x86). Not using them will give you "incorrect" values as the byte order isn't the same anymore.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

cecilio
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Fri Dec 03, 2004 8:44 am
Location: spain
Contact:

Post by cecilio » Tue Feb 08, 2005 8:00 am

Thank you very much for the answer.

I agree: it could be very useful in all functions related to reading, writing, importing and exporting data.

Are there other situations on which it is useful? Could I safely use int and long in the rest of the program?

Regards,
cecilio

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Tue Feb 08, 2005 9:13 am

cecilio wrote:Thank you very much for the answer.

I agree: it could be very useful in all functions related to reading, writing, importing and exporting data.

Are there other situations on which it is useful? Could I safely use int and long in the rest of the program?

Regards,
cecilio
Yes, because long on 64-bit machines is not the same as a 32-bit machine...
[Mostly retired moderator, still check in to clean up some stuff]

geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon » Tue Feb 08, 2005 11:14 am

"long on 64-bit machines is not the same as a 32-bit machine"

Is this a fact? I know this is how it was supposed to work, and it is how the "C++ for n00bs" books explains it.

But since virtually all C++ development has/is being done on a 32 bit platform, I would expect the compilers to continue to use 32 bits for an int, etc. Or at least include a -compability32 switch.

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Tue Feb 08, 2005 11:48 am

Code: Select all

//|Datatype 	LP64 	ILP64 	LLP64 	ILP32 	LP32
//|long 		64 	64 	32 	32 	32 
Alphas are LP64, so they would have 64-bit longs.

Of course, I'm not sure if there's some kind of compat switch though...
[Mostly retired moderator, still check in to clean up some stuff]

cecilio
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Fri Dec 03, 2004 8:44 am
Location: spain
Contact:

Post by cecilio » Tue Feb 08, 2005 11:50 am

"Yes, because long on 64-bit machines is not the same as a 32-bit machine..."

.... Well, this bring us to my initial point: Why to bother to use wxInt32 in declarations if when invoking a wxWidgets method it has parameters defined as long? If I compile on a machine of 64 bits I will get a lot of casting errors that will force me to do an explicit cast! isn't it?

What will be the advantage and were is the portability issue?

My point: unless internally developers of wxWidgets use xwInt32 (and the others) it will be of little use to use wxInt32,... instead of int, long,...

The only argument in favor is that of functions for dealing with importing and exporting data. But, what about the rest of the program? Seems to be useless.

Regards,
cecilio

leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio » Tue Feb 08, 2005 11:58 am

cecilio wrote:My point: unless internally developers of wxWidgets use xwInt32 (and the others) it will be of little use to use wxInt32,... instead of int, long,...

The only argument in favor is that of functions for dealing with importing and exporting data. But, what about the rest of the program? Seems to be useless.
Seems to sum up good. You as the application programmer know if you want int, long or wxInt32, as you know what the variable exactly stores. If you must rely on exact number of bytes, then use the wxInt32 kind of types. If you want the most efficient integer variable, use int (which should be the size of memory word - e.g fastest to copy around in one go) or something better suitable for the EXACT case. If you want the longest integer use long. Or if even longer - wxLongLong.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Tue Feb 08, 2005 12:00 pm

cecilio wrote: My point: unless internally developers of wxWidgets use xwInt32 (and the others) it will be of little use to use wxInt32,... instead of int, long,...
Well, this is kind of a loaded one...

Basically, in most places we don't use it because the native GUI functions are platform-specific and take the machine's long representation as an argument, for example...

cecilio wrote: What will be the advantage and were is the portability issue?
The main advantage is saving data to a disk between platforms (probably the main one) - if you save a file on a windows pc, you're going to have to swap the bytes of everything you read in - thus what you save needs to be defined bittage like 32...
cecilio wrote: The only argument in favor is that of functions for dealing with importing and exporting data. But, what about the rest of the program? Seems to be useless.
That's the main use. There are other cases when you need to know the exact number of bits in a variable like when you do math stuff or whatnot...
[Mostly retired moderator, still check in to clean up some stuff]

cecilio
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Fri Dec 03, 2004 8:44 am
Location: spain
Contact:

Post by cecilio » Tue Feb 08, 2005 1:19 pm

Thank you very much for your explanations and comments.

I think i've got a clearer picture of all this issue.

Regards,
cecilio

Post Reply