<p>What considerations do I need to make if I want my code to run correctly on both 32bit and 64bit platforms ?</p>

<p>EDIT: What kind of areas do I need to take care in, e.g. printing strings/characters or using structures ?</p>

[{'answer_id': 32539, 'author': 'Adam Haile', 'author_id': 194, 'author_profile': 'https://Stackoverflow.com/users/194', 'pm_score': 0, 'selected': False, 'text': '<p>I assume you are still talking about <em>compiling</em> them separately for each individual platform?  As running them on both is completely doable by just creating a 32bit binary.</p>\n'}, {'answer_id': 32542, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 0, 'selected': False, 'text': "<p>The biggest one is making sure you don't put pointers into 32-bit storage locations.</p>\n\n<p>But there's no proper 'language-agnostic' answer to this question, really.  You couldn't even get a particularly firm answer if you restricted yourself to something like standard 'C' or 'C++' - the size of data storage, pointers, etc, is all terribly implementation dependant.</p>\n"}, {'answer_id': 32545, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 1, 'selected': False, 'text': "<p>One solution would be to target a virtual environment that runs on both platforms (I'm thinking Java, or .Net here).</p>\n\n<p>Or pick an interpreted language.</p>\n\n<p>Do you have other requirements, such as calling existing code or libraries?</p>\n"}, {'answer_id': 32547, 'author': 'sparkes', 'author_id': 269, 'author_profile': 'https://Stackoverflow.com/users/269', 'pm_score': 1, 'selected': False, 'text': '<p>The same things you should have been doing all along to ensure you write portable code :)</p>\n\n<p><a href="http://developer.mozilla.org/En/C___Portability_Guide" rel="nofollow noreferrer">mozilla guidelines</a> and the <a href="http://c-faq.com/questions.html" rel="nofollow noreferrer">C faq</a> are good starting points</p>\n'}, {'answer_id': 32552, 'author': 'Nick Berardi', 'author_id': 17, 'author_profile': 'https://Stackoverflow.com/users/17', 'pm_score': 0, 'selected': False, 'text': '<p>It honestly depends on the language, because managed languages like C# and Java or Scripting languages like JavaScript, Python, or PHP are locked in to their current methodology and to get started and to do anything beyond the advanced stuff there is not much to worry about.</p>\n\n<p>But my guess is that you are asking about languages like C++, C, and other lower level languages.</p>\n\n<p>The biggest thing you have to worry about is the size of things, because in the 32-bit world you are limited to the power of 2^32 however in the 64-bit world things get bigger 2^64.  </p>\n\n<p>With 64-bit you have a larger space for memory and storage in RAM, and you can compute larger numbers.  However if you know you are compiling for both 32 and 64, you need to make sure to limit your expectations of the system to the 32-bit world and limitations of buffers and numbers.</p>\n'}, {'answer_id': 32553, 'author': 'Jorge Córdoba', 'author_id': 2695, 'author_profile': 'https://Stackoverflow.com/users/2695', 'pm_score': 3, 'selected': True, 'text': '<p>Options:</p>\n\n<p>Code it in some language with a <a href="http://en.wikipedia.org/wiki/Virtual_machine" rel="nofollow noreferrer">Virtual Machine</a> (such as Java)</p>\n\n<p>Code it in .NET and don\'t target any specific architecture. The <a href="http://www.dotnet-guide.com/jit.html" rel="nofollow noreferrer">.NET JIT compiler</a> will compile it for you to the right architecture before running it.</p>\n'}, {'answer_id': 32554, 'author': 'Dana the Sane', 'author_id': 2567, 'author_profile': 'https://Stackoverflow.com/users/2567', 'pm_score': 0, 'selected': False, 'text': '<p>In C (and maybe C++) always remember to use the sizeof operator when calculating buffer sizes for malloc. This way you will write more portable code anyway, and this will automatically take 64bit datatypes into account.</p>\n'}, {'answer_id': 32561, 'author': 'Evan Shaw', 'author_id': 510, 'author_profile': 'https://Stackoverflow.com/users/510', 'pm_score': 0, 'selected': False, 'text': "<p>In most cases the only thing you have to do is just compile your code for both platforms. (And that's assuming that you're using a compiled language; if it's not, then you probably don't need to worry about anything.)</p>\n\n<p>The only thing I can think of that might cause problems is assuming the size of data types, which is something you probably shouldn't be doing anyway. And of course anything written in assembly is going to cause problems.</p>\n"}, {'answer_id': 32587, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 0, 'selected': False, 'text': '<p>Keep in mind that many compilers choose the size of integer based on the underlying architecture, given that the "int" should be the fastest number manipulator in the system (according to some theories).</p>\n\n<p>This is why so many programmers use typedefs for their most portable programs - if you want your code to work on everything from 8 bit processors up to 64 bit processors you need to recognize that, in C anyway, int is not rigidly defined.</p>\n\n<p>Pointers are another area to be careful - don\'t use a long, or long long, or any specific type if you are fiddling with the numeric value of the pointer - use the proper construct, which, unfortunately, varies from compiler to compiler (which is why you have a separate typedef.h file for each compiler you use).</p>\n\n<p>-Adam Davis</p>\n'}]
['https://Stackoverflow.com/questions/32533', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/381/']