portability

Portable Compare And Swap (atomic operations) C/C++ library?

帅比萌擦擦* 提交于 2019-11-27 10:52:59
Is there any small library, that wrapps various processors' CAS-like operations into macros or functions, that are portable across multiple compilers? PS. The atomic.hpp library is inside boost::interprocess::detail namespace. The author refuses to make it a public, well maintained library. Lets reopen the question, and see if there are any other options? Intel Threading Building Blocks has a nice portable atomic<T> template which does what you want. But whether it is a small library or not can of course be debated.. OPA (Open Portable Atomics) could be a good fit for your needs. https://trac

Proper shebang for Python script

痞子三分冷 提交于 2019-11-27 09:46:10
问题 I'm usually using the following shebang declaration in my Python scripts: #!/usr/bin/python Recently, I've came across this shebang declaration: #!/usr/bin/env python In the script documentation, it was noted that using this form is "more portable". What does this declaration mean? How come there's a space in the middle of the path? Does it actually contribute to protability? 回答1: #!/usr/bin/env python is more portable because in general the program /usr/bin/env can be used to "activate" the

How to determine integer types that are twice the width as `int` and `unsigned`?

泪湿孤枕 提交于 2019-11-27 09:44:56
Values of intermediate multiplication typically need twice the number of bits as inputs. // Example int foo(int a, int b, int carry, int rem) { int2x c; // Some type that is twice as wide at `int` c = (int2x)a * b + carry; return (int) (c % rem); } Considering the potential for padding, (which appears to limit sizeof() usefulness) and non-2`s complement integers (which limits bit dibbling), ... Does the following always create the needed type? If not, how to code at least a reasonable solution, even if not entirely portable? #include <limits.h> #include <stdint.h> #if LONG_MAX/2/INT_MAX - 2 ==

Is there any guidance on converting existing .NET class libraries to portable libraries?

拈花ヽ惹草 提交于 2019-11-27 09:40:09
问题 I have some class libraries with a non-trivial amount of existing code. The class libraries currently target .NET 4.0. Is there any guidance on how to convert these libraries to be portable libraries? From looking at the .csproj, it doesn't appear that there are a lot of differences: <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> and <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B

Why does C++ parameter scope affect function lookup within a namespace?

做~自己de王妃 提交于 2019-11-27 09:19:41
This seems a little backwards to me but it works: #include <iostream> namespace nTest { struct cTest {}; void fTest(cTest& x) { std::cout << "nTest::fTest(cTest&) called" << std::endl; } } int main(void) { nTest::cTest x; fTest(x); //Weird! fTest is resolved since its parameter belongs to nTest. return 0; } Normally, you would need nTest:: in order to access fTest, but its parameter which belongs to nTest appears to add nTest to the list of possible scopes in which to search for fTest. It seems odd to me that the parameter scope influences the function lookup. This compiles fine in GCC, but I

Portable end of line (newline)

时间秒杀一切 提交于 2019-11-27 09:15:44
It's been an unpleasant surprise that '\n' is replaced with "\r\n" on Windows, I did not know that. (I am guessing it is also replaced on Mac...) Is there an easy way to ensure that Linux, Mac and Windows users can easily exchange text files? By easy way I mean: without writing the file in binary mode or testing and replacing the end-of-line chars myself (or with some third party program/code). This issue effects my C++ program doing the text file I/O. ybungalobill Sorry for partial overlap with other answers, but for the sake of completeness: Myth: endl is 'more portable` since it writes the

Byte precision pointer arithmetic in C when sizeof(char) != 1

穿精又带淫゛_ 提交于 2019-11-27 07:37:27
问题 How can one portably perform pointer arithmetic with single byte precision? Keep in mind that: char is not 1 byte on all platforms sizeof(void) == 1 is only available as an extension in GCC While some platforms may have pointer deref pointer alignment restrictions, arithmetic may still require a finer granularity than the size of the smallest fundamental POD type 回答1: Your assumption is flawed - sizeof(char) is defined to be 1 everywhere. From the C99 standard (TC3), in section 6.5.3.4 ("The

how portable is end iterator decrement?

邮差的信 提交于 2019-11-27 07:11:11
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. I think this is the relevant clause: ISO/IEC 14882:2003 C++ Standard 23.1.1/12 – Sequences Table 68 lists

How portable is the re-entrant qsort_r function compared to qsort?

我与影子孤独终老i 提交于 2019-11-27 06:44:51
问题 qsort_r() is the re-entrant version of qsort() which takes an additional 'thunk' argument and passes it into the compare function and I'd like to be able to use it in portable C code. qsort() is POSIX and everywhere but qsort_r() seems to be a BSD extension. As a specific question, does this exist or have an equivalent in the Windows C runtime? 回答1: I've attempted to write a portable version of qsort_r / qsort_s (called sort_r) shown with an example. I've also put this code in a git repo

Cross-platform way of constructing an FS path with Qt [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-11-27 06:42:08
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Qt equivalent of PathAppend? Short story: does Qt 4 have an analog of Python's os.path.join ? Long story: I need to add a relative path to the application directory, QCoreApplication::applicationDirPath() in the Right Way (TM), so that the code doesn't depend on the file system directory separator character. Is merely joining QStrings and using "/" as the separator a good solution? 回答1: You can either use "/"