Usage of wxInt16 and int Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
furries
Experienced Solver
Experienced Solver
Posts: 53
Joined: Wed Jun 29, 2005 3:45 pm

Usage of wxInt16 and int

Post by furries »

Hello,

I'd just like to clarify the usage of wxInt16, should it be used to replace int or is int ok to use as standard? My understanding was that int would not port to devices such as Palm whereas wxInt16 would.

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

Re: Usage of wxInt16 and int

Post by upCASE »

furries wrote: I'd just like to clarify the usage of wxInt16, should it be used to replace int or is int ok to use as standard? My understanding was that int would not port to devices such as Palm whereas wxInt16 would.
Actually wxInt16 is just a typedef for signed short. Using int is perfectly fine, but there's a little bit more to wxInt16: It does some automatic byte swapping when needed. For PowerPC platforms, wxInt16 is allways byte swapped, meaing the endianess is changed from little endian (Intel platforms) to big endian (Mac). You can however use int and do the swapping yourself if needed using the wxINTXX_SWAP_XXX() macros.
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
furries
Experienced Solver
Experienced Solver
Posts: 53
Joined: Wed Jun 29, 2005 3:45 pm

Post by furries »

I see, so when for MacOS I will need to add #ifdefs to convert?

Ok, I have a few other questions about types too;

LPCTSTR - pointer to a string? So I can replace with wxString*?

UINT - not sure what I should replace this with!
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

furries wrote:I see, so when for MacOS I will need to add #ifdefs to convert?
Using wxInt16 you don't have to, using int you'll need to swap bytes before using values (loading saved docs, recieved transmission etc.)
furries wrote: LPCTSTR - pointer to a string? So I can replace with wxString*?
LPCSTR -> CHAR* -> char*
I depends on what you want to do. To construct a wxString from char* use either string = char_array, or wxString string(char_array).
To get a wxStringas a char*, use one of the xxx_str() functions, like c_str(), mb_str() etc.
furries wrote: UINT - not sure what I should replace this with!
UINT -> unsigned int
Should be wxUint16
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
furries
Experienced Solver
Experienced Solver
Posts: 53
Joined: Wed Jun 29, 2005 3:45 pm

Post by furries »

Thankyou upCASE, you're a hive of information as ever! :)
Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi »

Actually LPCTSTR is typedef'ed to const TCHAR*...
So you should use const wxChar* instead...

Also UINT is 32 bits as far as I know (modern compilers treat 'int' as 32bits), so you should use wxUint32.

Hope this clarifies stuff...
furries
Experienced Solver
Experienced Solver
Posts: 53
Joined: Wed Jun 29, 2005 3:45 pm

Post by furries »

That does further clarify it, is there a list of types and their relevant converstions anywhere?
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Ups, right, 32 bits, sorry for that one.

http://www.wxwidgets.org/manuals/2.6.2/ ... rdermacros
There's a list of byte order macros to use.
The types are:
wxInt32
wxUint32
wxInt16
wxUint16

There's also wxLongLong, for 64 bit values. For compilers that don't support 64 bit variables, wxWidgets "emulates" this type. Normaly newer compilers should support "long long" or "__int64" as types. In that case wxLongLong is only a define for the correct type.
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
Post Reply