Thursday, July 25, 2013

Programming in C++ for both 32-bit and 64-bit

Newsgroup: comp.lang.c++

Subject: Re: Programming in C++ for both 32-bit and 64-bit

From: Paavo Helde <myfirstname@...>

Date: Thu, 25 Jul 2013 15:22:06 -0500



"Qu0ll" <Qu0llSixFour@...> wrote in

news:ZZKdnYzsgvR6mGzMnZ2dnUVZ_g6dnZ2d@...



> What are the main issues when developing software with C++ which needs

> to support both 32-bit and 64-bit operating systems?

>

> Is C++ code portable across these different architectures?



Sure one can write portable code for those architectures as well as for a

lot of others.



> Any special "gotchas" in writing portable C++ code of this nature?



You might want to avoid long datatype, it has different size on different

64-bit platforms. Use int64_t, uint64_t instead if your algorithm

requires more than 32 bits.



Beware that size_t will be different in 32-bit and 64-bit architectures.



When converting pointers into integers or vice versa (this is not ultra-

portable anyway) make sure that the integer has matching size.



Use std::string::size_type for storing string indices. Especially the

std::string::npos constant is very 64-bit on 64-bit platforms and

comparing it with any 32-bit index always yields false.



Not directly related to portability, but make sure time_t and file

offsets are always 64-bit even in 32-bit compilations.



Use typedefs for things which might change in the future, so you can

change a single typedef when this happens. It is also a good idea to use

short typedefs for long typenames as std::string::size_type.



hth

Paavo









via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?50961-Programming-in-C-for-both-32-bit-and-64-bit&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment