portability

Swap 2 values of 2 variables without using a third variable; python

偶尔善良 提交于 2019-11-29 12:24:35
So, a friend of mine asked how my python programming was coming; I said I was learning a lot and that it was coming along nicely. Then my friend, a math-snob, asks me: "Can you swap the value of 2 variables without using a third variable as a temporary placeholder?" Sylvain Leroux The canonical way to swap two variables in Python is a, b = b, a Please note than this is valid whatever the "type" of a or b is (numeric, string, tuple, object, ...). Of course, it works too if both variables reference values of different types. As many imperative languages, Python evaluates assignments right to

How similar/different are gnu make, microsoft nmake and posix standard make?

时光毁灭记忆、已成空白 提交于 2019-11-29 11:31:38
问题 How similar/different are gnu make, microsoft nmake and posix standard make? Obviously there's things like "which OS?", "which compiler?" and "which linker?", but I'm referring specifically to the syntax, semantics and command-line options of the makefiles themselves. If I write makefiles based on manuals for gnu make, what are the most important portability issues that I need to be aware of? 回答1: GNU Make and POSIX Make share a common core so that GNU Make understands makefiles intended for

What is the most portable/cross-platform way to represent a newline in go/golang?

倖福魔咒の 提交于 2019-11-29 10:54:19
问题 Currently, to represent a newline in go programs, I use \n . For example: package main import "fmt" func main() { fmt.Printf("%d is %s \n", 'U', string(85)) } ... will yield 85 is U followed by a newline. However, this doesn't seem all that cross-platform. Looking at other languages, PHP represents this with a global constant ( PHP_EOL ). Is \n the right way to represent newlines in a cross-platform specific manner in go / golang? 回答1: I got curious about this so decided to see what exactly

_Pragma preprocessor operator in Visual C++

北战南征 提交于 2019-11-29 10:47:28
Is there something like the ANSI C operator _Pragma in Visual C++? For example, I'm trying to define the following macro: #ifdef _OPENMP #define PRAGMA_IF_OPENMP(x) _Pragma (#x) #else // #ifdef _OPENMP #define PRAGMA_IF_OPENMP(x) #endif // #ifdef _OPENMP So I can circumvent compiler warnings for unknown #pragma omp ... in older GCC compilers. Is there a similar means available in VisualC++? Yes, but it's two underscores: __pragma I'm not sure about how the omp pragma works, however, here's an example using VC++'s optimize pragma: #define PRAGMA_OPTIMIZE_OFF __pragma(optimize("", off)) // These

Which parts of the python standard library are guaranteed to be available? [closed]

喜欢而已 提交于 2019-11-29 09:51:23
I'm interested to know which parts of the python standard library are absolutely guaranteed to be available, and which parts might not be installed, dependent on distribution. I've seen this question but it doesn't quite provide the answer I'm looking for. I'm aware that these modules aren't always available and that the math module always is . How about other modules? Are there any modules besides math that are guaranteed to be available? Edit: the sys module is also always available . If you are talking about the standard Python implementation (CPython), then the http://docs.python.org/3

Why and how are C++ bitfields non-portable?

烈酒焚心 提交于 2019-11-29 09:37:33
I've come across many comments on various questions regarding bitfields asserting that bitfields are non-portable, but I've never been able to find a source explaining precisely why. At face value, I would have presumed all bitfields merely compile to variations of the same bitshifting code, but evidently there must be more too it than that or there would not be such vehement dislike for them. So my question is what is it that makes bitfields non-portable? Bit fields are non-portable in the same sense as integers are non-portable. You can use integers to write a portable program, but you

Are there fixed size integers in GCC?

廉价感情. 提交于 2019-11-29 09:35:52
On the MSVC++ compiler, one can use the __int8 , __int16 , __int32 and similar types for integers with specific sizes. This is extremely useful for applications which need to work with low-level data structures like custom file formats, hardware control data structures and the like. Is there a similar equivalent I can use on the GCC compiler? Jason Coco ISO standard C, starting with the C99 standard, adds the standard header <stdint.h> that defines these: uint8_t - unsigned 8 bit int8_t - signed 8 bit uint16_t - unsigned 16 bit int16_t - signed 16 bit uint32_t - unsigned 32 bit int32_t -

How to print types of unknown size like ino_t?

不打扰是莪最后的温柔 提交于 2019-11-29 09:07:33
I often experience situations where I want to print with printf the value of an integer type of implementation-defined size (like ino_t or time_t ). Right now, I use a pattern like this for this: #include <inttypes.h> ino_t ino; /* variable of unknown size */ printf("%" PRIuMAX, (uintmax_t)ino); This approach works so far but it has a couple of disadvantages: I have to know whether the type I'm trying print is signed or unsigned. I have to use a type cast that possibly enlarges my code. Is there a better strategy? #include <inttypes.h> ino_t ino; /* variable of unknown size */ /* ... */ printf

Program portability

我只是一个虾纸丫 提交于 2019-11-29 06:29:45
问题 How to make sure that my program will be fully portable? 回答1: 1. Test This is a necessary but not a sufficient condition for doing anything properly. To test portability, you'll want multiple platforms and compilers. 2. Write to the standard, not to your development platform. This means, only do something if the standard says you can do it. Only expect a particular result if the standard says you can expect it. Only use a library or API if the standard says it exists. The standard is

Portable serialisation of IEEE754 floating-point values

徘徊边缘 提交于 2019-11-29 06:11:14
I've recently been working on a system that needs to store and load large quantities of data, including single-precision floating-point values. I decided to standardise on network byte order for integers, and also decided to store floating point values in big-endian format, i.e.: |-- Byte 0 --| |-- Byte 1 -| Byte 2 Byte 3 # ####### # ####### ######## ######## Sign Exponent Mantissa 1b 8b, MSB first 23b, MSB first Ideally, I want to provide functions like htonl() and ntohl() , since I have already been using these for swabbing integers, and I also want to implement this in a way that has as