portability

how portable is end iterator decrement?

自闭症网瘾萝莉.ら 提交于 2020-02-09 05:08:27
问题 Just encountered decrement of end() iterator in my company source codes and it looks strange for me. As far as I remember this was working on some platforms, but not for the others. Maybe I'm wrong, however I couldn't find anything useful in standard about that. Standard only says that end() returns an iterator which is the past-the-end value, but is it guaranteed to be decrementable? How does code like that match the standard? std::list<int>::iterator it = --l.end(); Thanks in advance. 回答1:

How to tell whether an executable was compiled for the present machine?

不打扰是莪最后的温柔 提交于 2020-01-30 06:48:07
问题 I have some c code that I compile and run, in a directory that is accessible from many different unix computers (various linux and mac, occasionally others), with different OS's obviously needing different executables. I have a simple shell script that invokes the appropriate executable, prog.$OSTYPE.$MACHTYPE , compiling it first if necessary. This is very simple (although it requires using csh in order to have $OSTYPE and $MACHTYPE be reliably defined) and it almost works. However, it turns

How to tell whether an executable was compiled for the present machine?

孤者浪人 提交于 2020-01-30 06:45:13
问题 I have some c code that I compile and run, in a directory that is accessible from many different unix computers (various linux and mac, occasionally others), with different OS's obviously needing different executables. I have a simple shell script that invokes the appropriate executable, prog.$OSTYPE.$MACHTYPE , compiling it first if necessary. This is very simple (although it requires using csh in order to have $OSTYPE and $MACHTYPE be reliably defined) and it almost works. However, it turns

c# databases for wp7, pc and xbox

风格不统一 提交于 2020-01-24 01:10:49
问题 I am currently working on a game in c# that I want to put on the market for windows 7, windows phone mango, and Xbox 360. Which SQL package will be portable across all 3 platforms for a database that I need? 回答1: SQLite is almost definitely your best bet if you want the same database backend over all three platforms. There is a port of it for windows phone 7, there is a really good .NET library for windows, and apparently is no problem on XNA. The only one of those three platforms I've used

How portable is code with #pragma optimize?

。_饼干妹妹 提交于 2020-01-23 07:20:12
问题 How portable is code that uses #pragma optimize? Do most compilers support it and how complete is the support for this #pragma ? 回答1: #pragma is the sanctioned and portable way for compilers to add non-sanctioned and non-portable language extensions * . Basically, you never know for sure, and at least one major C++ compiler (g++) does not support this pragma as is. * : From the C++ standard (N3242): 16.6 Pragma directive [cpp.pragma] A preprocessing directive of the form # pragma pp-tokens

C/C++ algorithm to produce same pseudo-random number sequences from same seed on different platforms? [duplicate]

家住魔仙堡 提交于 2020-01-21 03:44:32
问题 This question already has answers here : Consistent pseudo-random numbers across platforms (6 answers) Closed 6 years ago . The title says it all, I am looking for something preferably stand-alone because I don't want to add more libraries. Performance should be good since I need it in a tight high-performance loop. I guess that will come at a cost of the degree of randomness. 回答1: Any particular pseudo-random number generation algorithm will behave like this. The problem with rand is that it

Is there a portable equivalent to DebugBreak()/__debugbreak?

萝らか妹 提交于 2020-01-19 03:18:34
问题 In MSVC, DebugBreak() or __debugbreak cause a debugger to break. On x86 it is equivalent to writing "_asm int 3", on x64 it is something different. When compiling with gcc (or any other standard compiler) I want to do a break into debugger, too. Is there a platform independent function or intrinsic? I saw the XCode question about that, but it doesn't seem portable enough. Sidenote: I mainly want to implement ASSERT with that, and I understand I can use assert() for that, but I also want to

Is there a portable equivalent to DebugBreak()/__debugbreak?

谁说胖子不能爱 提交于 2020-01-19 03:18:04
问题 In MSVC, DebugBreak() or __debugbreak cause a debugger to break. On x86 it is equivalent to writing "_asm int 3", on x64 it is something different. When compiling with gcc (or any other standard compiler) I want to do a break into debugger, too. Is there a platform independent function or intrinsic? I saw the XCode question about that, but it doesn't seem portable enough. Sidenote: I mainly want to implement ASSERT with that, and I understand I can use assert() for that, but I also want to

Is std::vector::begin() - 1 undefined?

一曲冷凌霜 提交于 2020-01-16 09:09:28
问题 I need to iterate over some elements in backward order and I'm using: for ( /* ... */ it = vec.end() - 1, end = vec.begin() ; it >= end ; --it ) { // ... I now that end() - 1 is defined for some containers, including vector, but now I need to know if begin decrement is also defined. EDIT I don't know if I could use reverse_iterator, because I'll need to pass these iterators as parameters to std::vector::erase and from the documentation, it looks that they are different types. 回答1: Yes, it is

Storing a 32 bit float in a file portability concerns

霸气de小男生 提交于 2020-01-15 05:08:27
问题 If I store a float in a file via this code fwrite((void*)(&v), sizeof(v), 1, f); // v is a float. how often will a program reading the file with this code cause a runtime error because float is 8 bytes instead of 4? float v; fread((void*)(&v), sizeof(v), 1, f); return v; Can I always read 4 bytes and cast that to an 8 byte float? Would that be more portable? Emphasis on different Windows Platforms 64 bit vs 32 bit. 回答1: I would be less worried about the size of the float and more worried