cross-platform

What is the correct way to read sys.stdin in iPython qtconsole

社会主义新天地 提交于 2019-12-12 15:14:12
问题 I'm trying to write a library that will work as well across platforms as standard Python, iPython and within qtConsole. Everything works except my keyboard interaction. I want things like 'press any key' or 'press Y/N/Esc' In Windows this is easy with msvcrt and kbhit. (though I've not tried qtconsole in windows) In Linux this works using stdin and termios under both Python and iPython. The trouble is it seems qtconsole uses non-blocking stdin and does not support termios. You would think

Cross-platform definition of _byteswap_uint64 and _byteswap_ulong

﹥>﹥吖頭↗ 提交于 2019-12-12 15:08:41
问题 Visual Studio defines _byteswap_uint64 and _byteswap_ulong in stdlib.h. Am I right to assume, that this is not standard and won't compile on Linux or Darwin? Is there a way to define these includes in a cross-platform way? 回答1: Google's CityHash source code uses this code: https://github.com/google/cityhash/blob/8af9b8c2b889d80c22d6bc26ba0df1afb79a30db/src/city.cc#L50 #ifdef _MSC_VER #include <stdlib.h> #define bswap_32(x) _byteswap_ulong(x) #define bswap_64(x) _byteswap_uint64(x) #elif

release mode uses double precision even for float variables

此生再无相见时 提交于 2019-12-12 14:59:57
问题 My algorithm is calculating the epsilon for single precision floating point arithmetic. It is supposed to be something around 1.1921e-007. Here is the code: static void Main(string[] args) { // start with some small magic number float a = 0.000000000000000013877787807814457f; for (; ; ) { // add the small a to 1 float temp = 1f + a; // break, if a + 1 really is > '1' if (temp - 1f != 0f) break; // otherwise a is too small -> increase it a *= 2f; Console.Out.WriteLine("current increment: " + a

How to write a compile-time initialisation of a 4 byte character constant that is fully portable

我是研究僧i 提交于 2019-12-12 14:14:40
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 5 years ago . The (legacy) code looks roughly like this. #define MAKEID(a,b,c,d) (((UInt32)a)<<24 | ((UInt32)b)<<16 | ((UInt32)c)<<8 | ((UInt32)d) ) #define ID_FORM MAKEID('F','O','R','M') //... struct S { int id; int x; double d; // other stuff }; //... S s; socket.read(&s, sizeof(s)); // read network data over struct if (s.id == ID_FORM) { } The code reads a stream of

Read odd addresses, half words?

北慕城南 提交于 2019-12-12 13:36:15
问题 It's common knowledge that many CPU architectures (ARM, PPC) can not read odd addresses but will generate an exception if forced too, and yet others can, but do so slightly slower. (x86) But is there any CPU which can only address full 32 bit (or even larger!) words? I.e. it can not address 16 bit words? Perhaps amd64? I am trying to write a portable yet fast C malloc like allocator and want to align my memory accesses properly. Currently I am targeting ARM, i386 and amd64, and these I could

How to I get crosstool-ng C++ compiler working

喜你入骨 提交于 2019-12-12 12:12:37
问题 I'm trying to get crosstool-ng working with both C and C++. Even though I've selected C++ while using menuconfig, it doesn't seem to get built. The gcc compiler works as expected but not g++ I'm not sure what I'm doing wrong so any help would be appreciated. I followed the steps found here: Building embedded ARM systems with Crosstool-NG $ arm-unknown-linux-gnueabi-cpp main.cpp -o test arm-unknown-linux-gnueabi-cpp: main.cpp: C++ compiler not installed on this system NOTE: there is no arm

Cross-platform paths in CMake

瘦欲@ 提交于 2019-12-12 11:19:38
问题 I have a project I can build on both Linux and Windows using CMake. The only issue is that Unix-style paths, in CMakeLists.txt, can't work on Windows (which uses backslashes instead of slashes, also requiring the drive letter). Is there any way I can write a cross-platform CMakeLists.txt? 回答1: You question affects different details: Just don't use backslashes. Windows will also process slashes. Don't use drive letters. Use relative paths everywhere. GET_FILENAME_COMPONENT(X "${CMAKE_CURRENT

How can I start a .NET application from Java on Linux, Mac and Windows?

给你一囗甜甜゛ 提交于 2019-12-12 11:06:15
问题 I want to start a .NET application (compatible with Mono) from the context of a Java environment. My guess would be that I'd have to somehow figure out if mono is installed, find the location and start that using the .NET application path as a parameter. But what is a robust way to do it? Or is there a better way? Perhaps I should clarify the context: the Java part is running as a plugin in an environment with limited interaction possible, so I would really prefer to find a way without having

What is the right approach to encapsulate platform specific code in Go?

ぃ、小莉子 提交于 2019-12-12 10:50:17
问题 I want to develop a small Go application, which shows the used key stroke shortcuts to the audience of a presentation. To hook into the keyboard events I will have to use some platform specific code. What is the Go way to encapsulate platform specific code? I've been searching for keywords like compiler switch or platform modules, but I couldn't really find something about. 回答1: The solution to platform specific code is the build constraints. A build constraint, also known as a build tag, is

When using Mono Touch can I also package for a standard Window application?

☆樱花仙子☆ 提交于 2019-12-12 10:49:09
问题 I know that Mono Touch enables developing with nearly one source code and deploy to Android, iOs and Windows Mobile. There will of course be 3 projects and some platform related code but I will have important common code in C#. But I also need my development to work on standard Windows 7 and 8 (non mobile). Can I do this with Mono Touch and I yes what is the development process ? 回答1: I think you should check out my answer to this question: Consuming ViewModels in MonoDroid / MonoTouch In